Re: Double value is rounded to unexpected value: 2.5 -> 2 instead of 3

2017-07-08 Thread alex_ca via Digitalmars-d-learn
Thanks, that was what was happening.

Re: Double value is rounded to unexpected value: 2.5 -> 2 instead of 3

2017-07-07 Thread ag0aep6g via Digitalmars-d-learn
On 07/07/2017 08:29 PM, alex_ca wrote: I'm having trouble understanding why in some cases a double value will be rounded up and other times down, for the same code. Here's a snippet with code I tried to debug: int getNumberOfStitchesForRowLength(double rowLength) { writeln("input

Re: Double value is rounded to unexpected value: 2.5 -> 2 instead of 3

2017-07-07 Thread Ali Çehreli via Digitalmars-d-learn
On 07/07/2017 11:29 AM, alex_ca wrote: > input 2.5 10 10 > stitches: 2.5 -> 2 > I expect: 3 That's because what is printed as 2.5 is actually a little less than that. (Try printing with a format string like "%.20f".) The common way of dealing with this issue is to add 0.5 before the

Double value is rounded to unexpected value: 2.5 -> 2 instead of 3

2017-07-07 Thread alex_ca via Digitalmars-d-learn
Hi, I'm having trouble understanding why in some cases a double value will be rounded up and other times down, for the same code. Here's a snippet with code I tried to debug: int getNumberOfStitchesForRowLength(double rowLength) { writeln("input ", rowLength, " ",