|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Re: printf problem
To print floats you can always use a little manipulation like:
Code:
#define ACCURACY 1000 //How many decimal places are important to you
float f;
int i, i2; // Might need to be longs if you have a lot of significant digits
f = 245.56;
/* Print float value */
i = (int) f;
i2 = (int) ((f-i)*ACCURACY);
printf("f = %d.%d \r", i, i2); //e.g., f = 245.559
Last edited by Mark McLeod : 30-01-2005 at 12:29. |
|
#2
|
|||||
|
|||||
|
Re: printf problem
Quote:
|
|
#3
|
|||||
|
|||||
|
Re: printf problem
Quote:
We should verify that the leading zeros can be forced. I'll call one of my kids later to test it on the controller at school to be sure. [edit] That is supported (and has been tested), so the corrected printf would read: Code:
printf("f = %d.%03d \r", i, i2);
Last edited by Mark McLeod : 31-01-2005 at 14:11. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming Problem: Extremely Frustrating | chantilly_team | Programming | 19 | 12-02-2005 23:00 |
| printf problem | cbolin | Programming | 4 | 09-11-2004 02:44 |
| Anyone with a replacement Printf? | Larry Barello | Programming | 5 | 19-03-2004 02:20 |
| The problem with scouting... | archiver | 2001 | 10 | 23-06-2002 23:49 |
| Major problem with chipphua motors | aka Scott White | Motors | 18 | 19-03-2002 19:44 |