AtomSoft Well-Known Member Sep 9, 2010 #1 Hey guys just want to ask what could be a simple question. Im using sprintf to output numbers into string format which is working well. But i would like 2 characters. Like when i have a char and the number is anywhere from 0 to 9 i get 0 to 9 but i would like to get 00-09.. get it? I usually get: 0 1 2 3 4 5 6 7 8 9 10 - FIRST 2 CHARACTERS I would like: 00 01 02 03 04 05 06 07 08 09 10 Is it possible to some how force this in sprintf? or should i simply: Code: if(Data< 10){ sprintf(Data2,"0%d\0",Data); } else { sprintf(Data2,"%d\0",Data); }
Hey guys just want to ask what could be a simple question. Im using sprintf to output numbers into string format which is working well. But i would like 2 characters. Like when i have a char and the number is anywhere from 0 to 9 i get 0 to 9 but i would like to get 00-09.. get it? I usually get: 0 1 2 3 4 5 6 7 8 9 10 - FIRST 2 CHARACTERS I would like: 00 01 02 03 04 05 06 07 08 09 10 Is it possible to some how force this in sprintf? or should i simply: Code: if(Data< 10){ sprintf(Data2,"0%d\0",Data); } else { sprintf(Data2,"%d\0",Data); }
3v0 Coop Build Coordinator Forum Supporter Sep 9, 2010 #2 printf("%03d\n",b); In this example the 0 following the % indicates to show leading zeros. The 3 is the field width The d is decimal. So if b was 8 it would print 008
printf("%03d\n",b); In this example the 0 following the % indicates to show leading zeros. The 3 is the field width The d is decimal. So if b was 8 it would print 008
AtomSoft Well-Known Member Sep 9, 2010 #3 So : b = 4 printf("%02d\n",b); Would output : 04 b = 12 printf("%02d\n",b); Would output : 12 Correct? or would b=12 output 012?
So : b = 4 printf("%02d\n",b); Would output : 04 b = 12 printf("%02d\n",b); Would output : 12 Correct? or would b=12 output 012?
AtomSoft Well-Known Member Sep 9, 2010 #5 Just wanted to say thanks again and have a look: ADT 12232 V10