cast(int) getting an unexpected number

Joel Christensen joelcnz at gmail.com
Thu Nov 5 23:01:52 PST 2009


Seems random. I've got it working though, changed real to float. I seem 
to get different results with my little test program though.

Here's from my full program. (I think there's a function in phobos to do 
this any way):

char[] cashToString(dub money,char[] paddingForCents="".dup) {
   char[] amount;
   if ( money<1f ) {
     float cents=money*100f;
     amount=format("%s%d",paddingForCents,cast(int)cents);
   }
   else
     amount=format("%0.2f",money);
   return
     format("%s%s%s", money>=1f ? "$" : "", amount, money<1f ? "c" : "");
}


More information about the Digitalmars-d-learn mailing list