I\'m trying to compare two strings, but I fail achieving that. Why?
#include
#include
int main(){
float a = 1231.23123;
If you want a set number of digits to compare against in a string, use the precision specifier in sprintf
- %.5f
, and as others have pointed out, the number you've picked cannot be represented by a float
, but can be represented by a double
. i.e.
double a = 1231.23123;
char b[32];
sprintf(b, "%.5f",a);