Click here to Skip to main content
15,885,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
one text file always give me string like 2,500.4522 or 1,235.96,15,15,522.566
like values,
my question arises when i used
CString str="99,520.255";
float val;
val=atof(str,BUFFER,10);

Gets value val=99.00000

i'm so confused what to do?
ALL help are welcome
Posted
Comments
Ed Nutting 7-Jun-11 2:15am    
Not sure if this actually makes a difference but is it anything to do with dots and commas meaning different things between countries. It may be treating a comma as a UK dot and a dot as a UK comma ;P
Coder Block 7-Jun-11 2:21am    
What then?

1 solution

some modification given below
1.atof() takes one argument.
2.use double instead of float since your data seems to be of double size
3.remove comma with just one CString funation call Remove().

i hope following may help you

CString str="99,520.255";
str.Remove(',');
double val;
val=atof(str);
 
Share this answer
 
Comments
Coder Block 7-Jun-11 2:20am    
Hey,
what about 33,21,525.200
Resmi Anna 7-Jun-11 2:31am    
it will remove all commas(','). try this code. it will work
hakz.code 7-Jun-11 4:25am    
it works!My 5
Joan M 7-Jun-11 10:46am    
Simple and direct, my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900