Floating Point Variables sprintf Problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi

   

I need to use sprintf function with float numbers. But it does not work. 

   
    

         val=1.2243;
        sprintf(text,"Value=%f",(float)val);

    

        LCD_Position(0u,0u);
        LCD_PrintString(text);

   
   

Is there a setting in this regard?

   
    

 

   
0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

To get sprintf() running you need to

   

    #include <stdio.h>
    Set "use newlib nano"
    Set "Use newlib nano float formatting" in Build Settings -> Linker
    And increase heap size to 0x0200 in system view.

   


Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

To get sprintf() running you need to

   

    #include <stdio.h>
    Set "use newlib nano"
    Set "Use newlib nano float formatting" in Build Settings -> Linker
    And increase heap size to 0x0200 in system view.

   


Bob

0 Likes

I am not able to find how to add:

  "Use newlib nano float formatting" in Build Settings -> Linker

or how to change heap size to 0x200.

I'm using DAVE v4 so perhaps the UI for the options has changed.   Oddly, sprintf with float was working, then mysteriously stopped.   I'm suspecting heap, but can't seem to figure out how to change that with project properties.

 

 

0 Likes
Anonymous
Not applicable

Thanks Bob,

   

I'm Fixed it

0 Likes