dimanche 19 janvier 2020

How to use std::to_string function to format float as “x.0”

I am using std::to_string function to convert float to string.

 float number = 30.0f;  // this number will vary

when i convert the float number to string

 std::to_string(number);

the std::cout shows the result as 30.000000

i want the result as 30.0 and remove the extra zeros.

Aucun commentaire:

Enregistrer un commentaire