C -- Copy float to string
-
Hi Friends, I would like to know is there any otherway to copy a double to string in C. I see that it can be done by using sprintf(.. , "%f", .. ) but I want to know anyother way to do this. My problem is: If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen. Ur help is highly appreciated.. Thanks a lot.. Regards, Leela
-
Hi Friends, I would like to know is there any otherway to copy a double to string in C. I see that it can be done by using sprintf(.. , "%f", .. ) but I want to know anyother way to do this. My problem is: If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen. Ur help is highly appreciated.. Thanks a lot.. Regards, Leela
std::istringstream
? my mistake, this is C++. useftoa()
as an alternative, but never forget that the number is the number. your problem is a matter of representation (the decimal character - '.' or ',' - is not stored in the number itself)
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
Hi Friends, I would like to know is there any otherway to copy a double to string in C. I see that it can be done by using sprintf(.. , "%f", .. ) but I want to know anyother way to do this. My problem is: If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen. Ur help is highly appreciated.. Thanks a lot.. Regards, Leela
-
std::istringstream
? my mistake, this is C++. useftoa()
as an alternative, but never forget that the number is the number. your problem is a matter of representation (the decimal character - '.' or ',' - is not stored in the number itself)
Don't know where to start ?
Refer the Forums Guidelines and ask a friendHe asked to do that in C, not in C++ :rolleyes:
Cédric Moonen Software developer
Charting control [v1.1] -
std::istringstream
? my mistake, this is C++. useftoa()
as an alternative, but never forget that the number is the number. your problem is a matter of representation (the decimal character - '.' or ',' - is not stored in the number itself)
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
Hi Friends, I would like to know is there any otherway to copy a double to string in C. I see that it can be done by using sprintf(.. , "%f", .. ) but I want to know anyother way to do this. My problem is: If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen. Ur help is highly appreciated.. Thanks a lot.. Regards, Leela
This is controle by the
LOCALE
. I'm not certain that you can force sprintf to a certain representation ( . instead of , ) ?
Maximilien Lincourt Your Head A Splode - Strong Bad
-
std::istringstream
? my mistake, this is C++. useftoa()
as an alternative, but never forget that the number is the number. your problem is a matter of representation (the decimal character - '.' or ',' - is not stored in the number itself)
Don't know where to start ?
Refer the Forums Guidelines and ask a friendtoxcct wrote:
use ftoa() instead
Such as this implementation?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi Friends, I would like to know is there any otherway to copy a double to string in C. I see that it can be done by using sprintf(.. , "%f", .. ) but I want to know anyother way to do this. My problem is: If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen. Ur help is highly appreciated.. Thanks a lot.. Regards, Leela
ToughGuy9 wrote:
If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen.
If I understand you correctly, you want numbers formatted like 123,456.78 regardless of the locale. Is that correct?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
This is controle by the
LOCALE
. I'm not certain that you can force sprintf to a certain representation ( . instead of , ) ?
Maximilien Lincourt Your Head A Splode - Strong Bad
Maximilien wrote:
I'm not certain that you can force sprintf to a certain representation ( . instead of , ) ?
Not until
_sprintf_l()
came along. That might not be an option for the OP, however.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
ToughGuy9 wrote:
If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen.
If I understand you correctly, you want numbers formatted like 123,456.78 regardless of the locale. Is that correct?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi Friends, I would like to know is there any otherway to copy a double to string in C. I see that it can be done by using sprintf(.. , "%f", .. ) but I want to know anyother way to do this. My problem is: If i run the sprintf (.., "%f", .. ) on any machine in which has decimal point as , (comma) instead of a . (dot) (like French) it is converting . to , in the string even if the double value is having .(dot) . I don't want it to happen. Ur help is highly appreciated.. Thanks a lot.. Regards, Leela
Hi, Thanks to One and all for trying to help me in this regard,, As of now after copying the double to the string i.e., after sprintf statement Iam checking if string has , using strchr().. If i find a ,(comma) iam replacing it with a . (dot). But if can find some other alternative in which i can copy the value in the double variable as it is to a String.. Btw the double variable has value with .(dot) - Leela
-
Hi David, I want the double to be stored into the integer string as with decimal point as dot (.) but NOT as a , comma. Regards, Leela
But why would you want to do this for countries that format numbers differently?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb