std.format and floating point issue

jmh530 john.michael.hall at gmail.com
Wed Nov 1 21:00:12 UTC 2017


On Wednesday, 1 November 2017 at 19:06:42 UTC, Ali Çehreli wrote:
> On 10/29/2017 03:13 AM, codephantom wrote:
>> Can anyone help me to understand why the format in the second 
>> writeln below, does not format the output with commas?
>> 
>> --------------------------------
>> 
>> void main()
>> {
>>      import std.stdio, std.format;
>> 
>>      writeln( format("%,.1f", 84543432.951172) ); // 
>> 84,543,433.0
>>      writeln( format("%,.0f", 84543432.951172) ); // 84543433
>> 
>> }
>> 
>> ------------------------------
>
> Thanks for letting me know about this new feature. :) I agree 
> with you that it's a bug.
>
> Ali

Was just looking at the examples on std.format. There is also 
this:
writeln(format("%,f", 1234567.891011)); // "1,234,567.891,011"
which is what you would expect, I suppose, but still isn't what 
anyone would want. What you'd want is
writeln(format("%,.0f", 1234567.891011)); // "1,234,567"
which may not currently be tested.

Someone should file a bug report.


More information about the Digitalmars-d-learn mailing list