Page 2 of 2

Re: Format Numbers

Posted: Mon Mar 29, 2010 9:31 pm
by Frarth
WilliamL wrote:That's a good question. I'm using StrF(#,number of digits after decimal point) and it seems to round up (the rules are made by StrF() ). There needs to be more thought in how the rounding is done. I was most interested in getting, for example the floating 12.34 to be converted into a string as '12.34' and not '12.3399999', and not the problem of 3.66666 being rounded up or 3.3333 not being rounded up.

Actually, this was just an exercise and this was a way to clarify my thinking of how the process could be done. I think it would be nice if a single format function could be developed for everyone (multi-platform) to use in place of having a format function built-in in pb. I am certainly not offering this as that example but as encouragement for further development which might not be this code at all.
StrF() is less accurate than StrD(). Look at what my code above does with:

Code: Select all

Debug FormatF(12.34, "##.########")
Debug FormatD(12.34, "##.########")
'12.3399999', is normal because Single floating point is only accurate up to 7 digits (including decimal point) Anyone correct me if I'm wrong.

Re: Format Numbers

Posted: Mon Mar 29, 2010 10:02 pm
by WilliamL
[deleted]

Re: Format Numbers

Posted: Mon Mar 29, 2010 10:29 pm
by Frarth
I'd say, keep things simple. Format procedures for different types usually work faster. Also, I'm not exactly sure what you try to do with US currency. Placing the right symbol in front, isn't that enough?

Re: Format Numbers

Posted: Mon Mar 29, 2010 10:38 pm
by Kaeru Gaman
putting a $ in front of a number will cause Str() to interprete it as Hex.

however, float is not suitable for currency.
use quad and calculate in 1/10 or 1/100 cent, insert a comma for output only.

Re: Format Numbers

Posted: Mon Mar 29, 2010 10:38 pm
by WilliamL
You got that right! I know what I do with (currency), I spend it and there is never enough. :mrgreen:

@Kaeru - I agree with you! I wrote my accounting program using integers then a format procedure for display.