Terribletrux

Moving decimal places

8 posts in this topic

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)??

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Thank you spudw2k & FireFox for your quick replies. I will investigate these options further, have a good weekend.

Share this post


Link to post
Share on other sites

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

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now