After making calculations with the decimal values, for example, you may need to convert back to metric prefixes. Let's look at how that works.
Step 1: Decide how many places to the left or right to shift the decimal point and select the corresponding metric prefix. For example, if you shift it left by 3, that’ll be k (kilo), or if you shift it left by 3 more (for a total of 6), that’ll be M (mega). For shifting to the right, 3 would be m (milli), 6 would be µ (micro), and so on… Tip: Make sure to use multiples of 3.
Step 2: Find the decimal value for the metric prefix in the SI Metric Prefixes table and make a fraction of metric prefix / decimal value.
Step 3: Multiply your quantity by the fraction.
Step 4: Calculate the result.
Example: Convert 38,000 Hz so that it has a metric prefix. Hint: In engineering notation, it’s usually preferable for the integer part of the quantity to be in the 1...999 range.
Here are examples of how metric prefixes change the schematics you’ve been working with. Again, shoot for an integer portion in the 1...999 range.
Remember from earlier, how if you multiply some quantity by 1, the result is that same quantity? The example started with 1000 = k and divided both sides of the equal sign by k for a result of 1 = 1000 / k. You could divide both sides by 1000 instead for 1 = k / 1000. Then, starting with 2000 Ω, you can multiply by k / 1000. The thousands cancel, and the result is 2 kΩ.
(View full size: muam-multiply-by-one-val-to-prefix.mp4 [1])
The scrip values_to_metric_prefixes converts decimal values to quantities with metric prefixes. It is similar to the previous example program, but there are two main differences. First, values_to_metric_prefixes is not using special formatting strings to ensure that the values display as decimal (instead of sometimes displaying exponential notation). Second, this conversion is the inverse of the previous conversion. In this script, the value-to-quantity conversion is done with division:
quantity = value / (10 ** exponent)
In the previous example, the quantity to value conversion was done with multiplication:
value = quantity * (10 ** exponent)
Since 1 x 103 is 1000, it can also be used in place of the prefix k. This same rule applies to all rows in the SI Metric Prefixes table on this page. [2]. Just remember to use the rules of scientific notation in your calculations!
(View full size: muam-multiply-by-one-sci-note.mp4 [3])
The values_to_metric_prefixes script converts values to quantities with metric prefixes.
# values_to_metric_prefixes prefix_exponents = {'M':6, 'k':3, 'm':-3, 'u':-6} print("Enter decimal value and metric prefix") print("Result will be quantity and prefix.") print() while True: text = input("Enter value: ") value = float(text) prefix = input("Enter metric prefix: ") exponent = prefix_exponents[prefix] quantity = value / (10 ** exponent) unit = input("Enter unit: ") prefix_unit = prefix + unit print("Value:", quantity, prefix_unit) print()
This script converts decimal values to quantities and metric prefixes.
Links
[1] https://learn.parallax.com/sites/default/files/content/Python/Elec/muam-multiply-by-one-val-to-prefix.mp4
[2] https://learn.parallax.com/node/2443
[3] https://learn.parallax.com/sites/default/files/content/Python/Elec/muam-multiply-by-one-sci-note.mp4
[4] https://learn.parallax.com/node/2444
[5] https://learn.parallax.com/node/2447
[6] https://python.microbit.org/v/2