Thread overview | |||||
---|---|---|---|---|---|
|
October 29, 2017 std.format and floating point issue | ||||
---|---|---|---|---|
| ||||
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 } ------------------------------ |
November 01, 2017 Re: std.format and floating point issue | ||||
---|---|---|---|---|
| ||||
Posted in reply to codephantom | 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
|
November 01, 2017 Re: std.format and floating point issue | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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.
|
Copyright © 1999-2021 by the D Language Foundation