|
|
View previous topic :: View next topic |
Author |
Message |
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
Point's in LCD |
Posted: Thu Aug 26, 2004 12:20 pm |
|
|
Using 2x20 LCD, I must printf to LCD value float , but how put to this
value after cents, thouthands, millions
example:
value = 9123567,5 in float
at LCD I must printf: 9.123.567.5 of ... |
|
|
Ttelmah Guest
|
Re: Point's in LCD |
Posted: Thu Aug 26, 2004 2:39 pm |
|
|
Userrr wrote: | Using 2x20 LCD, I must printf to LCD value float , but how put to this
value after cents, thouthands, millions
example:
value = 9123567,5 in float
at LCD I must printf: 9.123.567.5 of ... |
If this is being used for currency, forget floats, and use a 32bit integer instead. Otherwise you will have perpetual errors from the rounding inherent in floats. Have the integer count in 'cents', and it will be exact.
There are two different approaches to outputing the number. First, printf it, to a _fixed length_ output string, using sprintf. Use the option to display leading zeros, so the digits will allways be in the same place in the string. Then start at the left end of the string, use a counter to know where in the string you are, skip the zeros, and output the digits from the string when you get to them. When the counter corresponds to the positions you want the markers added, send these.
Alternatively, you can extract digits from a number using division, and subtraction, and use these the same way. However again the numeric accuracy of floats will give problems.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|