Home > Enterprise >  Converting floating point value to string using gcvt(), but when there are no decimals the whole num
Converting floating point value to string using gcvt(), but when there are no decimals the whole num

Time:10-11

Just hopefully a simple question about the gcvt() function. Printing out buffer as a result of gcvt(32.000,10,buffer), results in "32." Any way I can get rid of that annoying dot after the 32?

CodePudding user response:

I don't think you can get gcvt to not do that - you can remove it afterward with

if ((p=strchr(buffer,'.'))
    *p='\0';

CodePudding user response:

As usual after posting took me 10 mins to figure out a solution.... gcvt is depreciated and I was set on using that because after hours of something not working this helped it work. Anyway, the best way to do this is to use sprintf(buffer, "%f", float_value); Literally does the same thing and no dot at the end!

  •  Tags:  
  • c
  • Related