normandbr
(Fresh Scripter)
2005-11-17 04:27 AM
Adding number and multiplication

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.


Les
(KiX Master)
2005-11-17 04:52 AM
Re: Adding number and multiplication

So what is the problem?

$result = 45.0 * 0.067


Howard Bullock
(KiX Supporter)
2005-11-17 04:56 AM
Re: Adding number and multiplication

What version of KiXtart are you using? Try using 4.51.

Richard H.Administrator
(KiX Supporter)
2005-11-17 09:34 AM
Re: Adding number and multiplication

The expression "45 * .067" will not work because
  1. .067 is not a valid number - you need to prefix the zero so it is 0.067
  2. 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) ?



Les
(KiX Master)
2005-11-17 03:18 PM
Re: Adding number and multiplication

My answer has a better golf score.

Richard H.Administrator
(KiX Supporter)
2005-11-17 03:48 PM
Re: Adding number and multiplication

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


Les
(KiX Master)
2005-11-17 03:59 PM
Re: Adding number and multiplication

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.


normandbr
(Fresh Scripter)
2005-11-18 02:22 AM
Re: Adding number and multiplication

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.


Les
(KiX Master)
2005-11-18 02:29 AM
Re: Adding number and multiplication

Quote:

Please just right me an example of small script to get a result with decimal and i will go from there.



I did.

$result = 45.0 * 0.067

What version @KiX?


normandbr
(Fresh Scripter)
2005-11-18 02:52 AM
Re: Adding number and multiplication

Version 4.51
I did this script
$result = 45.0 * 0.067
? $result
and the result is 0


Les
(KiX Master)
2005-11-18 03:00 AM
Re: Adding number and multiplication

Are you sure that the KiX is version 4.51? Maybe there is another version on the path?

Try the following:

Code:
Break on
@KiX ?
$result = 45.0 * 0.067
$result ?



The result I get is:
Quote:

4.51
3.015

C:\KiXScripts>




normandbr
(Fresh Scripter)
2005-11-18 03:03 AM
Re: Adding number and multiplication

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.


LonkeroAdministrator
(KiX Master Guru)
2005-11-18 03:07 AM
Re: Adding number and multiplication

is this your whole script or do you have something else in it?
what is your OS language?


normandbr
(Fresh Scripter)
2005-11-18 03:11 AM
Re: Adding number and multiplication

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.


Les
(KiX Master)
2005-11-18 03:18 AM
Re: Adding number and multiplication

Strange...
Test it on another computer. That one is FUBAR'd.


normandbr
(Fresh Scripter)
2005-11-18 03:26 AM
Re: Adding number and multiplication

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.


Les
(KiX Master)
2005-11-18 03:28 AM
Re: Adding number and multiplication

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?

Les
(KiX Master)
2005-11-18 03:29 AM
Re: Adding number and multiplication

LOL

Frenched
Up
Beyond
All
Recognition


normandbr
(Fresh Scripter)
2005-11-18 03:34 AM
Re: Adding number and multiplication

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


Les
(KiX Master)
2005-11-18 03:45 AM
Re: Adding number and multiplication

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.


LonkeroAdministrator
(KiX Master Guru)
2005-11-18 04:14 AM
Re: Adding number and multiplication

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.