Float2String
De DigiWiki.
Example:
string myFormattedFloat = Float2String(-7.1373699, 3, TRUE);<br /> //rounded //returns "-7.14" string myFormattedFloat = Float2String(-7.1373699, 3, FALSE);<br /> //not rounded //returns "-7.13"
Specification:
string Float2String ( float num, integer places, integer rnd) { //allows string output of a float in a tidy text format //rnd (rounding) should be set to TRUE for rounding, FALSE for no rounding if (rnd) { float f = llPow( 10.0, places ); integer i = llRound(llFabs(num) * f); string s = "00000" + (string)i; // number of 0s is (value of max places - 1 ) if(num < 0.0) return "-" + (string)( (integer)(i / f) ) + "." + llGetSubString( s, -places, -1); return (string)( (integer)(i / f) ) + "." + llGetSubString( s, -places, -1); } if (!places) return (string)((integer)num ); if ( (places = (places - 7 - (places < 1) ) ) & 0x80000000) return llGetSubString((string)num, 0, places); return (string)num; }