Converting Engineering Units
Conversion of double values(0.0001)=>QString Units(100u) and Vice Versa.
If your working in the technical domain surely there will be situation where you need to convert double values like 0.0001V into QString units data like(100uV) for display purpose.For example to set in QLineEdit,QLabel etc..
And again for actual calculation you need it in double values.But it will be easy if you have a function to do this conversions.
For scenario,
If you need to increment/decrement the 100mV, first you need to convert Qstring 100mV into double 0.1(crop the 100 from 100mV,divide by 1000 to get 0.1) and then increment/decrement and again we need to convert into incremented 101mV(multiply 0.1 into 1000 and add convert into Qstring and add “mV” unit to it).
To make life easier,i created a code snippet with functions convertToUnits & convertToValues.It can converts units from nano, micro, milli, deci, kilo & Mega.
convertToUnits takes double 0.1 as input and returns Qstring 1000m.
convertToValues takes Qstring 1000m as input and returns double 0.1.
Look at the image below for example,
Functions code:
I also attached the Source Code [dl.dropboxusercontent.com] project file.
Hope it helped you.
Pls comment to me @ dreamerindia@gmail.com