Skip to content

Instantly share code, notes, and snippets.

@dpeek
Created September 12, 2012 03:57
Show Gist options
  • Save dpeek/3704205 to your computer and use it in GitHub Desktop.
Save dpeek/3704205 to your computer and use it in GitHub Desktop.
Formats a large float (eg Date.getTime) as a string with no exponent in cpp.
class FloatHelper
{
/**
Formats a large float (eg Date.getTime) as a string with no exponent in cpp.
1.347420344e+12 -> 1347420344000
*/
function formatFloat(float:Float):String
{
#if cpp
var str = Std.string(float);
var parts = str.split(".");
var exp = parts[1].split("e+");
return parts[0] + StringTools.rpad(exp[0], "0", Std.parseInt(exp[1]));
#else
return Std.string(float);
#end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment