#151628 - 2005-11-17 04:27 AM
Adding number and multiplication
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
Hello,
I am trying to add numbers or doing multiplication with decimals.
debug on open (1,result.txt,5) $a = 67.0 $b= 3.5 $d = $a + $b ;should be 70.5 $e = $a * $b ;should be 234.5 ? $d ? $e $d = ''+$d $e = ''+$e writeline (1,$d + @crlf + $e )
Does someone can help. I also got some calculation in a variable to do with many decimals, ex.: 45 * .067 and the result need to get 3 decimals.
|
Top
|
|
|
|
#151630 - 2005-11-17 04:56 AM
Re: Adding number and multiplication
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
What version of KiXtart are you using? Try using 4.51.
|
Top
|
|
|
|
#151631 - 2005-11-17 09:34 AM
Re: Adding number and multiplication
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
The expression "45 * .067" will not work because
- .067 is not a valid number - you need to prefix the zero so it is 0.067
- 45 is an integer, so 0.067 will also be coerced to an integer making the expression "45 * 0" which will give a result of zero.
If you are unsure of the variant sub-type of variables, use the C*() functions to cast the variable to the right type. See CInt(), CDbl() and so-on in the manual.
FormatNumber() will fix decimal places: Code:
FormatNumber(45.0 * 0.067,3) ?
|
Top
|
|
|
|
#151633 - 2005-11-17 03:48 PM
Re: Adding number and multiplication
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I'm assuming that the request for three decimal places in the output is a generic one rather than just that particular expression but I may have mis-understood the requirements.
Nice smiley
|
Top
|
|
|
|
#151635 - 2005-11-18 02:22 AM
Re: Adding number and multiplication
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
I did try all this and none is working, I never got a result with decimal. The number I want to use is in a variable like in my example at the beginning. I might be nuts but I can not make it work. Please just right me an example of small script to get a result with decimal and i will go from there. Thanks to all for your help.
|
Top
|
|
|
|
#151637 - 2005-11-18 02:52 AM
Re: Adding number and multiplication
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
Version 4.51 I did this script $result = 45.0 * 0.067 ? $result and the result is 0
|
Top
|
|
|
|
#151639 - 2005-11-18 03:03 AM
Re: Adding number and multiplication
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
My result is 4.51 0 No kidding, I ve copy and paste from the webpages. If i could get the same result as you, my problem would be fix.
|
Top
|
|
|
|
#151641 - 2005-11-18 03:11 AM
Re: Adding number and multiplication
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
My OS is windows 2000 pro. This is my whole script, well I add a line sleep 5 in order to view the result. Once i will be able to get a decimal result, I will be able to make the scrip I need.
|
Top
|
|
|
|
#151643 - 2005-11-18 03:26 AM
Re: Adding number and multiplication
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
Dit test on another computer the result was OK. I did put my decimal as a (,) in my regional setting instead of a period (.) on the other computer and it is now working fine.
Thanks a lot for your help, I really appreciate.
|
Top
|
|
|
|
#151646 - 2005-11-18 03:34 AM
Re: Adding number and multiplication
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
I am in Montreal Canada, I am setting computer with , or . for decimal. It did start working when I did change to , for decimal. Try it on your computer, just change for a . for decimal and you will see the result.
Thanks
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 557 anonymous users online.
|
|
|