Terribletrux Posted March 20, 2015 Share Posted March 20, 2015 Hello everyone, I'm trying to convert a number in nanowatts to watts, to do so I have to move the decimal 10−9. For example 5.6nW is the same as 0.0000000056W. I can't seem to figure out how to get AutoIT to show all the numbers. It seems I can only go as far as 10-4 before AutoIt converts the number back to exponent form. #include <MsgBoxConstants.au3> Local $num1 = 5.6 Local $num2 = 0 Do Local $Answer = ($num1/(10^$num2)) MsgBox($MB_SYSTEMMODAL, "", "The new number is " & $Answer) $num2 = $num2 + 1 Until $num2 = 9 Does anyone know of a different way to do this calculation and keep all the numbers (Zeros)?? Link to comment Share on other sites More sharing options...
spudw2k Posted March 20, 2015 Share Posted March 20, 2015 You could use the >BigNum UDF. #include <BigNum.au3> #include <MsgBoxConstants.au3> Local $num1 = 5.6 Local $num2 = 0 Do Local $Answer = (_BigNum_Div($num1,(10^$num2))) MsgBox($MB_SYSTEMMODAL, "", "The new number is " & $Answer) $num2 = $num2 + 1 Until $num2 = 9 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
FireFox Posted March 20, 2015 Share Posted March 20, 2015 Hi, Try this : #include <MsgBoxConstants.au3> #include <String.au3> Local $num1 = 5.6 Local $num2 = 0 Do Local $Answer = ($num1 / (10 ^ $num2)) $i = StringInStr($Answer, "e", 2) If ($i > 0) Then $Answer = "0." & _StringRepeat("0", Number(StringRight($Answer, 3))-1) & StringReplace(StringTrimRight($Answer, 5), ".", "") EndIf MsgBox($MB_SYSTEMMODAL, "", "The new number is " & $Answer) $num2 = $num2 + 1 Until $num2 = 9 Note that it doesn't support negative numbers, but it's not hard to change the code for it. Br, FireFox. Link to comment Share on other sites More sharing options...
Terribletrux Posted March 20, 2015 Author Share Posted March 20, 2015 Thank you spudw2k & FireFox for your quick replies. I will investigate these options further, have a good weekend. Link to comment Share on other sites More sharing options...
Solution Gianni Posted March 20, 2015 Solution Share Posted March 20, 2015 have also a look to the StringFormat function.... Local $num1 = 5.6 Local $num2 = 0 Do Local $Answer = ($num1 / (10 ^ $num2)) ConsoleWrite("The new number is " & $Answer & @TAB & StringFormat("%.10f", $Answer) & @CRLF) $num2 = $num2 + 1 Until $num2 = 10 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jchd Posted March 21, 2015 Share Posted March 21, 2015 Obviously StringFormat as above! This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
mikell Posted March 22, 2015 Share Posted March 22, 2015 Do you need this Do loop ? Local $num = 5.6 Msgbox(0,"", _Convert($num, 9) ) Func _Convert($n, $e) Return StringFormat("%." & $e+1 & "f", $n/(10^$e)) EndFunc Link to comment Share on other sites More sharing options...
Terribletrux Posted March 23, 2015 Author Share Posted March 23, 2015 Thank you for all the reply's, its greatly appreciated. Mikell, The Do Loop is not needed. It was just used to demonstrate my problem. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now