EPOS Java Number Rounding Problem
I am developing a java EPOS system and am having a strange issue with number accuracy that doesnt make any sense to me.
On a till system you have a user display of the form
0000000.00
When you type into this for example the number 7 then the number 8 it goes
0000000.07
0000000.78
Moving along the screen.
I cant figure out how to represent this accurately (ie using floats) but still have the functionality to append onto the float, not add to it.
i have come up with the following
Float tempNum = currentNum*10;
StringBuffer sb =new StringBuffer(tempNum.toString());
sb.append(i);
String s = sb.toString();
currentNum = Float.valueOf(s).floatValue();
updateOutputs();
With the basic idea being casting to a string buffer, appending then casting back of sorts but i get accuracy issues...
Pressing 7 a whole bunch of times gives 7777.9995 not 7777.77 etc
I know there must be a simple and more elegant way to solve this problem but i just cant seem to think around it right now.
Thanks
[1135 byte] By [
Dezila] at [2007-10-2 7:51:05]

Thanks for all the fast replies, really helped. Ive now got it working acurately which is great except when the integer is over 9 digits long i get some errors thrown.
This arrises when trying to convert the int to a stringbuffer. I assume the number is then too large so im just going to ignore input after 9 digits allowing the till to go up to 9,999,999.99 but how do you count the number of digits in an int? I think im just having a bad day here as i cant seem to figure it out. I have thought of converting it to a type that will allow me to do it but it seems really strange that i cant simply get a digit count?
Thanks
Dezila at 2007-7-16 21:38:47 >

This is an input panel on an EPOS system, but as im designing it for touch screen it has an on screen number pad and display of the number.
When the buttons are pressed for the numbers that number is appended to the internal integer storage value. Also the output string is updated.
Most till systems allow you to enter up to X digits until then ignore what you type or print an error, so i am happy to follow this behavior but require the digit count.
I hope that makes sense but if not my gui is similar to these...
http://www.tillrollshop.co.uk/asps/uploads/big/1205-1.jpg
http://www.mi-store.com/mi-store/Till_Main.jpg
The second image shows a number pad and label just like mine.
Thanks
Dezila at 2007-7-16 21:38:47 >
