Formatting -0.0 as 0.0

Steven Schveighoffer schveiguy at
Fri Oct 15 17:16:30 UTC 2021

On 10/15/21 11:18 AM, Bastiaan Veelo wrote:
> Thank you Steve.
> On Friday, 15 October 2021 at 14:09:32 UTC, Steven Schveighoffer wrote:
>> On 10/15/21 8:37 AM, Bastiaan Veelo wrote:
>>> What I would like best is if there were a format specifier flag that 
>>> does this conversion automatically, like "%> 4.3f". Does it make 
>>> sense to add this? Is there a better way?
>> The only way I can think of that isn't really intrusive (like your 
>> `posZero` thing) is to define your own `writef`/`format` wrappers 
>> (what I'd do is check any doubles, and replace them when necessary).
> The thing that is holding me back is that it feels backwards to wrap 
> `std` to fix what I perceive as a usability issue, contra fixing `std` 
> itself. Hence my proposal of extending the format specification -- 
> although I find it complicated enough as it is. I am surprised that I am 
> the first to have this problem.

Well, it's based on C's implementation, so you are definitely not the 
first ;)

That also has a good suggestion instead of using * 0, you can check if 
it's 0 and just assign 0 in that case.


More information about the Digitalmars-d mailing list