Page 1 of 2 12>
Topic Options
#151628 - 2005-11-17 04:27 AM Adding number and multiplication
normandbr Offline
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
#151629 - 2005-11-17 04:52 AM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
So what is the problem?

$result = 45.0 * 0.067
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151630 - 2005-11-17 04:56 AM Re: Adding number and multiplication
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
What version of KiXtart are you using? Try using 4.51.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#151631 - 2005-11-17 09:34 AM Re: Adding number and multiplication
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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) ?


Top
#151632 - 2005-11-17 03:18 PM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
My answer has a better golf score.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151633 - 2005-11-17 03:48 PM Re: Adding number and multiplication
Richard H. Administrator Offline
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
#151634 - 2005-11-17 03:59 PM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151635 - 2005-11-18 02:22 AM Re: Adding number and multiplication
normandbr Offline
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
#151636 - 2005-11-18 02:29 AM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151637 - 2005-11-18 02:52 AM Re: Adding number and multiplication
normandbr Offline
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
#151638 - 2005-11-18 03:00 AM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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>


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151639 - 2005-11-18 03:03 AM Re: Adding number and multiplication
normandbr Offline
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
#151640 - 2005-11-18 03:07 AM Re: Adding number and multiplication
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
is this your whole script or do you have something else in it?
what is your OS language?
_________________________
!

download KiXnet

Top
#151641 - 2005-11-18 03:11 AM Re: Adding number and multiplication
normandbr Offline
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
#151642 - 2005-11-18 03:18 AM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Strange...
Test it on another computer. That one is FUBAR'd.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151643 - 2005-11-18 03:26 AM Re: Adding number and multiplication
normandbr Offline
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
#151644 - 2005-11-18 03:28 AM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151645 - 2005-11-18 03:29 AM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
LOL

Frenched
Up
Beyond
All
Recognition
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151646 - 2005-11-18 03:34 AM Re: Adding number and multiplication
normandbr Offline
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
#151647 - 2005-11-18 03:45 AM Re: Adding number and multiplication
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.051 seconds in which 0.017 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org