Hello, i want to convert float to string with a format i needed, ex: float 23.33 to string 023.3 ; 2.56 to string 002.6; -45.66 to string -045.7 then print it via serial and store in SD Card. Could you suggest what function i should use? i will deal with negative number also so straight adding of leading zero depends on string length will cause error in the negative number. Before using arduino, i used to be a basic language(bascom) user, in bascom there is format and fusing. Thanks
ps: i had try using dtostrf which is only specify how many number behind the decimal separator, not how many in front of it
well, finally i decide to multiply my float by 100 then sprintf it as integer, that gives my what i want (i could later divide it again with 100 in the other end of the system) but i ran into another trouble. when dealing with negative number, the negative sign will consumes 1 places, thus reducing my resolution. Any idea how to solved this?
Separate the integer portion of the number from the fractional portion. Deal with the two parts as separate integers, after multiplying the fractional portion by some factor of 10, and rounding appropriately.