|
|
|||||||
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. |
||||||||
|
|
|||||||
So what is the problem? $result = 45.0 * 0.067 |
||||||||
|
|
|||||||
What version of KiXtart are you using? Try using 4.51. |
||||||||
|
|
|||||||
The expression "45 * .067" will not work because
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) ? |
||||||||
|
|
|||||||
My answer has a better golf score. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
I dunno... the formula I posted returns three decimal places (3.015) without FormatNumber()? As for those pesky smileys... I dunno... I just type a colon and a p and that shows up. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Quote: I did. $result = 45.0 * 0.067 What version @KiX? |
||||||||
|
|
|||||||
Version 4.51 I did this script $result = 45.0 * 0.067 ? $result and the result is 0 |
||||||||
|
|
|||||||
Are you sure that the KiX is version 4.51? Maybe there is another version on the path? Try the following: Code: Break on The result I get is: Quote: |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
is this your whole script or do you have something else in it? what is your OS language? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Strange... Test it on another computer. That one is FUBAR'd. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
I wonder... is KiX affected by localization? Your computer may be configured for other than the english regional settings. Don't some localizations replace the decimal place with a comma? |
||||||||
|
|
|||||||
LOL Frenched Up Beyond All Recognition |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
I recognize the French Canadian accent. My company's head office is in Montreal and I have worked there from time to time. Glad you got it sorted out. |
||||||||
|
|
|||||||
well, I asked for the OS language long time ago and never got a response. anyways, having the decimal point as "," in the regional settings does not affect kixtart behaviour. but, iirc, french windows does perform differently. anyway, might be something worth for calling ruud. |