Casting double to ulong weirdness
via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 24 15:52:04 PDT 2015
On Monday, 24 August 2015 at 22:12:42 UTC, H. S. Teoh wrote:
> On Mon, Aug 24, 2015 at 09:34:22PM +0000, via Digitalmars-d
> wrote: [...]
>> What is the correct way to truncate, not round, a
>> floating-point value to an integer?
>
> std.math.trunc.
>
>
> T
import std.stdio;
import std.math;
void main() {
double x = 1.2;
writeln(std.math.trunc(x * 10.0));
double y = x * 10.0;
writeln(std.math.trunc(y));
}
Outputs:
11
12
More information about the Digitalmars-d
mailing list