Sunday, 13 December 2015

Convert Float in to String in C


There is a very useful function called dtostrf() which will convert Float in to String

The syntax is 

dtostrf(float value,  String length,  Digits after decimal point, String buffer);


where

Float Value---------------------> Float value that we need to convert

String length--------------------> Total length of string including '.'

Digits after decimal point-----> Number of digits we wish to display after decimal point

String buffer--------------------> Buffer that we need to store converted string



 Example:

float Value = 987.67900;

char Str[15]; 

void setup() 
{  
    dtostrf(Val,7, 3, Str);  
   Serial.begin(9600); 
   Serial.println(Str);
}void loop()
{       
   ;

OutPut: 

987.679



No comments:

Post a Comment