/*************************************************************** * do_fraction * Inputs: * long double d : value to be fractionized. * int decplaces : number of fractional parts including the point. * * Returns: string : The fractionized number. * * Effect: * Returns a string from a long double. * Notes: * Use at your own peril. ***************************************************************/ char DECIMAL_POINT='.'; // use ',' in European locales string do_fraction(long double value, int decplaces=3) { ostringstream out; int prec = numeric_limits::digits10; // 18 out.precision(prec);//override default out< n+decplaces)) //is it followed by at //least decplaces digits? { str[n+decplaces]='\0';//overwrite first redundant digit } str.swap(string(str.c_str()));//get rid of spurious //characters after the nul return str; }