How to make a Currency class from std.BigInt?
Colin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 31 05:07:28 PST 2015
On Saturday, 31 January 2015 at 12:07:23 UTC, RuZzz wrote:
> How to get amount of digit after point in a double for to get
> integer from a double?
> assert(amountAfterPoint(1.456) == 3);
> assert(amountAfterPoint(0.00006) == 5);
How about a loop like
import std.stdio;
void main(){
writefln("%s", 1.45.numDigits);// prints 2
writefln("%s", 1.452343.numDigits);// prints 6
writefln("%s", 1.0.numDigits);// prints 0
}
long numDigits(double num){
long i=0;
double n=num;
while(true){
if(n - (cast(long)n) == 0){
return i;
}
i++;
n *= 10;
}
}
More information about the Digitalmars-d-learn
mailing list