mIRC Home    About    Download    Register    News    Help

Print Thread
$round() returning improperly #244103 24/01/14 05:09 AM
Joined: Dec 2002
Posts: 201
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 201
I found that while rounding negative numbers, the sign is kept no matter the result.. $round(-0.1,0) = -0

Re: $round() returning improperly [Re: Talon] #244117 24/01/14 02:14 PM
Joined: Mar 2008
Posts: 88
B
BhaaL Offline
Babel fish
Offline
Babel fish
B
Joined: Mar 2008
Posts: 88
With floating point numbers, theres a difference between +0 and -0 (which is the sign)
I'd expect this to be the case here, and I wouldn't want to "fix" that.

Does it break anything in particular for you?

Re: $round() returning improperly [Re: BhaaL] #244123 24/01/14 10:47 PM
Joined: Dec 2002
Posts: 201
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 201
mainly something that required the length of the number, which $len() returned 2 which baffled me, then I outputted the result and found that it was -0, a simple $calc() around $rand() fixes the issue tho.

Example:
$calc($round(-0.1,0))

Re: $round() returning improperly [Re: Talon] #244269 10/02/14 10:54 PM
Joined: Feb 2003
Posts: 2,681
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,681
Numbers rounded to 0 decimal places are now integers, and -0 should be rounded to 0 with no sign. It breaks sorting, too, ie $sorttok or /window -s


Well. At least I won lunch.
Good philosophy, see good in bad, I like!