double to String conversion
PlaneTeeR
Posts: 100
Hello everyone,
I'm facing a new problem. I have the BPI-216 LCD screen but in my program i'm working with doubles. You can't print Doubles to the LCD with the write functions. So i need to convert them. In PC java it is simple, but when i apply this to the javelin it says:
'Double is either a misplaced package name or non-existent entity'
The method i use is:
str = string to display
i = calculated double
String str = Double.toString(i);
Thanks Johnny
The Netherlands
I'm facing a new problem. I have the BPI-216 LCD screen but in my program i'm working with doubles. You can't print Doubles to the LCD with the write functions. So i need to convert them. In PC java it is simple, but when i apply this to the javelin it says:
'Double is either a misplaced package name or non-existent entity'
The method i use is:
str = string to display
i = calculated double
String str = Double.toString(i);
Thanks Johnny
The Netherlands
Comments
which is float, not double.
The Float32 package has a method print.
Your alternative is to write a print method for the double type,
stored in an 8-byte array.
regards peter
But i'm looking at the float32 class and can't find anything with print?
Remember that i need to have a string or stringbuffer·for the BPI216 LCD!
Thanks Johnny
http://www.parallax.com/javelin/underdev.asp
has method intValue() that converts to an int
and method toString() that converts a Float32 type to a String type
So if you have a variable
Float32 f = new Float32(12); //floating value 12.0
then f.toString() returns a String with content "12.0" or something like that.
Check the file for the specific format.
If you do not like the available format, copy and change the existing toString().
regards peter
I have this code as simple test code:
You see that I want to display object s, but I can't use the print method of Float32. The BPI216 class has the method write, in this you can send a String but how do i get my string there?
Thanks Johnny
To write to the LCD, use the same method to make a String as with System.out
··· myLCD.write(s.toString());
That should work.
regards peter
Thanks Peter for this, now I can work with the pulse readings again, i didn't finished that yet.
Johnny·
In embedded applications 99% can be done without FP, using only integer math.
regards peter
I've just tried the previous·java code·for real on my BOE·and i got this:
[noparse][[/noparse]Error IDE-0042] Unknown unhandled exeption in JVM (164).
And the number is not show on the LCD
What is this?
Thanks johnny
Unknown unhandled exception in JVM: [font=Arial,Arial size=2]This is an internal error. [/font][font=Arial,Arial size=2]Report error to technical support
Try the attachment. I added a try/catch.
regards peter
[/font]
thanks Johnny
My guess is, the try/catch block creates a slightly different bytecode sequence that is handled.
I have these errors also occasionally. The workaround is usually a try/catch or rewriting
some small piece of code (for example, changing a for-loop into a while-loop).
See if you can comment out the catch message. An empty catch block sometimes also works.
··· try {
····· myLCD.write(s.toString());
··· }
··· catch (Exception e) {
····· //System.out.println("An exception occured during LCD write");
··· }
regards peter
thanks for helping me solve this problem!
Coming back on the sensor readings, i'm making a bike computer and i need accurate readings, is the floating point not necessary on a bikecomputer?
thanks Johnny
you could use FP. But consider bike speed. Your bike speed is likely
to be less than 100 km/h so you could let the value 10000 represent 100.00 km/h
so your bike speed could be known to 2 decimals using integers.
It is all a matter of interpretation of numbers.
regards peter