Re: string to real conversion losing data

2010-04-10 Thread jicman
Ali Çehreli Wrote: > jicman wrote: > > Greetings and salutations! > > > > Will someone be so kind as to explain why this is happening? > > > > > > import std.stdio; > > import std.conv; > > > > void main() > > { > > char[][] strRealVals = > > [ > > "14539.34","1230.00","361.62","1

Re: string to real conversion losing data

2010-04-08 Thread Ali Çehreli
Ali Çehreli wrote: > Try for example "%.18f" for 'real'. Well... That will be too many digits unless the number of digits before the decimal point is zero. The decimal digits before and after the point should be 18 for most accurate representation. But the OP probably doesn't need that many

Re: string to real conversion losing data

2010-04-08 Thread Ali Çehreli
jicman wrote: Greetings and salutations! Will someone be so kind as to explain why this is happening? import std.stdio; import std.conv; void main() { char[][] strRealVals = [ "14539.34","1230.00","361.62","1613.10","","","0.00" ]; real rTotal = 0; foreach (char[] s; strReal

Re: string to real conversion losing data

2010-04-08 Thread jicman
wrzosk Wrote: > W dniu 08.04.2010 23:02, jicman pisze: > > > > it is looking ok to me, try this one and thing why it is like that :) > > > import std.stdio; > import std.conv; > > void main() > { > writefln(17744.06); > } Ok, I'll bite... I don't get it. does that mean that writefln is

Re: string to real conversion losing data

2010-04-08 Thread BCS
Hello bearophile, writefln("%.5f\n", tot); // 17744.06000 Never trust your output function :) (e.i. always check to see if it's doing what you think it is.) Back in the bad old days, a guy I knew spent a while debugging a problem that turned out to be that he was loading data as float but

Re: string to real conversion losing data

2010-04-08 Thread bearophile
> If I add these numbers, the outcome should be 17744.06. Any ideas? I am > using Digital Mars D Compiler v1.046. > josé This prints the same values, using latest D2: import std.stdio, std.conv; void main() { real tot = 0; foreach(el; ["14539.34","1230.00","361.62","1613.10","0.00"])

Re: string to real conversion losing data

2010-04-08 Thread wrzosk
W dniu 08.04.2010 23:02, jicman pisze: Greetings and salutations! Will someone be so kind as to explain why this is happening? import std.stdio; import std.conv; void main() { char[][] strRealVals = [ "14539.34","1230.00","361.62","1613.10","","","0.00" ]; real rTotal =