Normal Topic @decimal no longer rounds (Read 870 times)
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
@decimal no longer rounds
Dec 21st, 2005 at 10:07pm
Print Post Print Post  
Is this intentional? As per the manual, @decimal is failing to round.

Here's an example:

var v as double = 1.228
writeln(@decimal(v,2))

1.23

but instead, I'm getting

1.22

Am I missing something? Do I need to start using @round to get my money values correct?

Thanks,

Steve
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @decimal no longer rounds
Reply #1 - Dec 23rd, 2005 at 1:53am
Print Post Print Post  
No, you are not missing something. @Decimals was not supposed to round, but it did. So it got documented that it did. It was supposed to truncate (so as to be different from @round). The documentation will have to catch up (my fault...sorry. I miscommunicated to our technical writers). If you prefer rounding, use @round.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: @decimal no longer rounds
Reply #2 - Dec 23rd, 2005 at 3:46pm
Print Post Print Post  
Thanks, Mark.

I had been using @decimals for displaying and printing money values, but I will switch to @round instead.

Happy Holidays to you and your family!

Steve
  
Back to top
IP Logged
 
Alec
Lanticans
*****
Offline



Posts: 200
Location: Ascot, England, UK
Joined: Nov 22nd, 2002
Re: @decimal no longer rounds
Reply #3 - Dec 24th, 2005 at 8:59pm
Print Post Print Post  
Bear in mind that whereas @Decimals() returns a string value, @Round() returns a number. So if putting this in a text string you're probably going to want to wrap an @Str(), or an @Decimals(), around the @Round.

Eg:

vNumberString = @Str(@Round(MyNumber,2))
  

Alec
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: @decimal no longer rounds
Reply #4 - Dec 24th, 2005 at 9:55pm
Print Post Print Post  
Thank you, Alec.

I would not have thought to do that.

Happy Holidays!

Steve
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @decimal no longer rounds
Reply #5 - Dec 24th, 2005 at 10:00pm
Print Post Print Post  
Actually, Alec brings up a good point. If your LE is not formatted to two decimal places (or is a string LE) you might want to run the number through both @round (to round it) and @decimals (to set it to be a numeric string with the appropriate number of decimal places).
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: @decimal no longer rounds
Reply #6 - Dec 27th, 2005 at 3:23pm
Print Post Print Post  
Another good point.

Thank you both.

Steve
  
Back to top
IP Logged