0

I need to get ALL decimal numbers possible, but I have a limit of 19 number char on the spinbox. Setting a static numbers on how many decimal places will be and setting a static number of decimals (setDecimals()) is not acceptable since the value I am getting is dynamic.

For example, I want to convert Hertz:

Hertz: 1.00 Megahertz: 1e-6 GigaHertz: 1e-9

I want it to be in this format: 1.00, 0.000006, 0.000000009,

Yes! Decimal places are dynamic.

This is the code for conversion (Value of dictionary is not yet finished):

conversion_formula = {'Hz': 1, 'kHz': 1e-3, 'MHz': 1e-6, 'GHz': 1e-9, 's': 1, 'ms': 1e-3, 'us': 1e-6, 'ns': 1e-9, 'V': 1, 'mV': 1e-3}

if FREQUENCY_UNIT_NAME == title or AMPLITUDE_UNIT_NAME == title:
    output_value = input_value * (conversion_formula[current_unit] / conversion_formula[base_unit])
elif title == TIME_UNIT_NAME:
    output_value = input_value * (conversion_formula[base_unit] / conversion_formula[current_unit])
Tenserflu
  • 520
  • 5
  • 20

1 Answers1

1

The Python package to-precision does the job, as per this answer.

Michael Gecht
  • 1,374
  • 1
  • 17
  • 26