decimal_format.ash

Catch-22

Active member
As opposed to positive AND negative mumbers. Perhaps Veracity's statement would have been clearer if she'd written XOR instead of using words?

I also would've accepted NAND ;)

It only really becomes an issue if you are rounding large sets of numbers, which I would cringe at if you were using my function to do so :)

If cumulative error is a concern, do all your calculations on a set first and finally round the result once, before outputting to the user.

Bad:
Code:
a = Round(1.5)
b = Round(2.5)
c = Round(a+b)
print c

Good:
Code:
a = 1.5
b = 2.5
c = a+b
print round(c)
 

Bale

Minion
It's kinda cool that the new to_string(float, string) can do the work of this script in a single line, including rounding.

PHP:
to_string(myFloat, "%." + precision + "f");

Dang that's nice.
 
Last edited:

Catch-22

Active member
Yes, it's also much more useful as it implements a standard Java method at the back-end. Oh well, it was fun while it lasted :) time to figure out the next ridiculously overelaborate ASH function to write!
 

Catch-22

Active member
So, out of curiosity, I profiled the native ASH function vs. mine and the native function is almost exactly 5 times faster than mine. According to the profiler, on my PC it took 0.340582457 seconds for decimal_format to process 10000 conversions, whilst to_string took 0.068328504 seconds to process 10000 conversions. Proving, if anything, that Java processes strings quite quickly :)
 
Top