Q: os_sprintf.. : Float / Double

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Q: os_sprintf.. : Float / Double

Postby rudi » Fri Nov 14, 2014 3:33 am

hi guys

i play with float and double

Code: Select all


char temp[100];

os_sprintf(temp, " Where is my Float : %f \r", 12.34);
os_sprintf(temp, " Where is my Float : %2.2f \r", 12.34);
os_sprintf(temp, " Where is my Float : %.2f \r", 12.34);


get not the right formated string.

a try with %e and %E

Code: Select all

os_sprintf(temp, " Where is my Float : %e \r", 12.34);
os_sprintf(temp, " Where is my Float : %E \r", 12.34);


same.

how you format floats ;-) 12.34 ?

thank you!
best wishes
rudi ;-)

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
vishnu046
Posts: 8
Joined: Sat Nov 15, 2014 1:47 pm

Re: Q: os_sprintf.. : Float / Double

Postby vishnu046 » Mon Nov 17, 2014 6:39 pm

Hi rudy,

OS_SPRINTF doesnt supprot %f ...
i am using like this...
Attachments
iftoa.rar
to print float
(817 Bytes) Downloaded 1256 times
Vishnu

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Re: Q: os_sprintf.. : Float / Double

Postby rudi » Mon Nov 17, 2014 7:46 pm

vishnu046 wrote:Hi rudy,

OS_SPRINTF doesnt supprot %f ...
i am using like this...


hi vishnu ;-)


thank you so much for your effort and help.
i will test asap ;-) i search in
http://www.cs.fsu.edu/~baker/devices/lx ... t/printf.c
for making a function .. without boot.h ..
so you have save me the work
thank you!!
^^^^^^^^^^

best wishes rudi ;-)


btw: i help me in past like this way, this is a simple way in first step to get decimals..

Code: Select all


char temp[100];
char arraystring[5];
float adjustvalue = 1.5;   // my LM35 was difference 1.5 kelvin to the mechanical thermometer to much .. so i substrakt this from measuring value later..
float adc_value;
int decimal, whole;
...
...

adc_value = adc_read();
adc_value = ((adc_value * 1000 / 1024 / 9.31 ) - adjustvalue );
whole    = adc_value;
decimal = ( adc_value - whole ) * 10 ; // only deci ..

..
..

os_sprintf(arraystr, "%2d.%i", whole, decimal );  // look like 17.5
os_sprintf(temp,"Temp measuring was: %s °C", arraystr);
uart0_sendStr(temp);
..



or simple without the arraystr..

Code: Select all

os_sprintf(temp,"Temp measuring was: %2d.%i °C", whole, decimal);
uart0_sendStr(temp);


btw with esp-01 the adc measuring will be fine too, i attached the mod at a esp-01
add a LM35 to the adc pin and get the measuring too ;-)
i love espressif!!!
^^^^^

rudi ;-)

info for negative celsius..
my measuring is allways in + Celsius so i can work this in paste way.. but
if measuring value goes - Celsius, the formated value is

Code: Select all

-10.-3 °C

so must change the negative decimal .. i will test yours ;-) thank you!!!

edit'S: misspelling ..name
Attachments
templm35.JPG
templm35.JPG (50.73 KiB) Viewed 11984 times
IMG_3101.JPG
IMG_3101.JPG (81.59 KiB) Viewed 11984 times

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Who is online

Users browsing this forum: No registered users and 91 guests