Jump to content

Moving decimal places


Go to solution Solved by Gianni,

Recommended Posts

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

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
Link to comment
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.

Link to comment
Share on other sites

  • Solution

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...