go to http://www.fablefox.com
anyway, I haven't program in PB for more than a year already. So I wrote a simple app just out of boring. how do I print float just two digit after point. i know i can do it by change it to string, delete all charater after 2 from the point, and turn it back to float again.
any faster and easier way, hmmm?
my brain too rusty and right now i'm writing novel and try to learn piano anyway.
print float two digit after point
The problem with using floats like this is when converting back to a float. The inherent errors in rounding mean that you will likely not end up with just two decimal places etc. even when there is nothing wrong with your code.
E.g. the following will do as you requested:
but does not work properly because of the limitations with the representation of floating point numbers.
Your best bet is to follow your original plan, but keep the result in string form rather than convert back to a float.
E.g. the following will do as you requested:
Code: Select all
a.d = 6.1625
b.d=Int(100*a)/100
Debug bYour best bet is to follow your original plan, but keep the result in string form rather than convert back to a float.
I may look like a mule, but I'm not a complete ass.
Code: Select all
Debug StrF(6.1625, 2) ; for floats .f (32bits)
Debug StrD(6.1625, 2) ; for doubles .d (64bits)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: print float two digit after point
for printing, use a string. so just use the conversion like Flype posted.Fable Fox wrote:... how do I print float just two digit after point...
but do not convert it back into a float, do further calculations with the original float.
an other alternative is: use fixcomma-values.
if you are doing calculations with currency, it's better anyways.
oh... and have a nice day.
thank you!
Thanks everyone, I slept on the problem and realized that I only need it for the printing. So I use SearchString for "." and use Mid just to take that "." position plus two digit.
but there is a simple error, 1234.5678 will be 1234.56, and not 1234.57. I can do the calculation, but it's not a big thing anyway.
I'll check all suggestion for future releases.
Thanks
but there is a simple error, 1234.5678 will be 1234.56, and not 1234.57. I can do the calculation, but it's not a big thing anyway.
I'll check all suggestion for future releases.
Thanks
Re: thank you!
Fable Fox, what is it you don't like about StrF() ?
Code: Select all
Debug StrF(1234.5678, 2) ; outputs 1234.57
Good programmers don't comment their code. It was hard to write, should be hard to read.

