String Format in javelin
PlaneTeeR
Posts: 100
Hello everybody,
We have a problem with the display of our bikecomputer. We need to format the output numbers to 2 digits. We have a method in Java: String formattedValue = String.format("%5.2f",value); But the format method of String is not supported until version 1.5.0. Is there a method in javelin to do this?
Greetings
Johnny & Daniel
The Netherlands
We have a problem with the display of our bikecomputer. We need to format the output numbers to 2 digits. We have a method in Java: String formattedValue = String.format("%5.2f",value); But the format method of String is not supported until version 1.5.0. Is there a method in javelin to do this?
Greetings
Johnny & Daniel
The Netherlands
Comments
using
int k = 7;
Format.printf("%02d",k)
which will display 07
The Format class can be found here
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/
There is the f3 class that stores floats with 3 digit accuracy and it has
a printf() method (which calls Format to do the actual printing).
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/
The Format class can not print float values.
You may look at the Float32 class (32bit floats) for a print method
http://www.parallax.com/javelin/underdev.asp
regards peter
We will look into the code and try it on our stamp.
Johnny
I think my question was wrong! I meant i needed a fixed floating point, for example:
We get 3,445224 but we want to show it as 3,44.
Is that an option of this format class?
Thanks Johnny
intValue() converts a Float32 object (IEEE standard 784)
to an integer, so if you multiply your F by 100, then
convert to int R, then printf("%d.",R/100) and printf(%02d",R%100)
you get your 2 decimals.
The other method is toString, from which you can print characters
up to 2 decimals after the decimal point.
Question: the source obviously is pc java.
How do you calculate/receive your floats on the javelin (uM_FPU ??).
regards peter