Created
November 18, 2013 05:32
-
-
Save rpgmaker/7523009 to your computer and use it in GitHub Desktop.
Double To String (Improved)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string dtoa(double value) { | |
long trunc = (long)value; | |
double mantissa = (trunc < 0) ? value - trunc : trunc - value; | |
var left = (long)(1000000000000000 * (mantissa > 0 ? mantissa : -mantissa)); | |
char* buf = stackalloc char[64]; | |
char* bf = buf; | |
lltoa(bf, trunc); | |
if (value < 0) { | |
bf[0] = '-'; | |
} | |
while (*(++buf) != '\0') ; | |
*(++buf) = '.'; | |
lltoa(buf, left); | |
var str = new string(bf); | |
var cstr = String.Concat(ltoa(trunc), ".", ltoa(left)); | |
//return ""; | |
return String.Concat(ltoa(trunc), ".", ltoa(left)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment