Go Down

Topic: Fomratting numbers (Read 343 times) previous topic - next topic

TempleClause

Is there an easy way to format numbers?
I map the value of a potentiometer to 0 - 24 and if the value is < 10 it should do a leading 0.
So that it would print
00
01
02
03
..
09
10
11
and so on.

Of course I could do a simple if the value is < 10 but I thought maybe there is a built in function that does this.

Thanks

WizenedEE

#1
Jan 06, 2013, 11:20 pm Last Edit: Jan 07, 2013, 12:34 am by WizenedEE Reason: 1
Make a temporary buffer (EDIT: and use sprintf) or use this: http://arduino.cc/forum/index.php/topic,120440.0.html

0miker0

I did something like this for my real time clock to display a 01,02,02...
It has a lot of other junk in there but all it really does is push the number to the right and jam a zero in front if less than 0.

  char second[2];
  int tmpsecond = bcdToDec(Wire.receive());

  if(tmpsecond < 10)
  {
   second[1] = second[0];
   second[0] = '0';
  }
  uoled.TextGraphic(112,10,SMALL_FONT,0xFFFF,1,1,second,1);

robtillaart


a simple  if the value is < 10  construct  is far faster than sprintf which can handle many formatting commands
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up