ftoa

Jul 14, 2008 at 11:48pm
I need to write a code of ftoa (means float to alphabet)
I refered the content of itoa, but I sill have the problem to handle the digits after decimal point.

Are there some hints? (smile)
Not whole code is ok? hints make problem more fun
Jul 14, 2008 at 11:53pm
This'll work for Floats or Double

1
2
3
4
5
6
7
8
#include <sstream>

string convertDouble(double value) {
  std::ostringstream o;
  if (!(o << value))
    return "";
  return o.str();
}


Last edited on Jul 14, 2008 at 11:54pm
Jul 18, 2008 at 7:42am
<sorry I put the wrong info so removed it>

Eshwar
Last edited on Jul 19, 2008 at 1:25pm
Jul 18, 2008 at 10:49am
That isn't simpler, and it doesn't do the right thing. ftoa() converts a number to its character representation. That is, 12.34 --> "12.34".

Simply casting a number to a character just gives you the indexed character in whatever codeset you happen to be using (most people use ASCII, but there are a lot of variations.) That is, 65 --> "A".
Jul 19, 2008 at 1:24pm
oh sorry forgive me.

I mis understood ftoa
Jul 20, 2008 at 8:48am
I have already done it,
use itoa and multiply by 10 the decimal digits!
Last edited on Jul 20, 2008 at 12:22pm
Topic archived. No new replies allowed.