ftoa

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
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
<sorry I put the wrong info so removed it>

Eshwar
Last edited on
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".
oh sorry forgive me.

I mis understood ftoa
I have already done it,
use itoa and multiply by 10 the decimal digits!
Last edited on
Topic archived. No new replies allowed.