www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.format and floating point issue

reply codephantom <me noyb.com> writes:
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

}

------------------------------
Oct 29 2017
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Nov 01 2017
parent jmh530 <john.michael.hall gmail.com> writes:
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.
Nov 01 2017