C++ std::setprecision in C# -
i'm picking c# porting legacy c++ code , keep output identical. used along lines of output << std::setprecision(10) << (double) value; i figured be output.write("{0:f10}", value); but didn't trick. values > 1 more digits. common online suggestion math.round first, appends zeroes if total length < 10 . so put together: // std::setprecision not same ":f10", mirror original behavior static string setprecision(double value) { string ret = value.tostring(); // don't substring(0, 11), need apply rounding, // , don't this, don't want append zeroes, // 10 digits + period, 0.. not counting total if(ret.length > digits + 1) ret = math.round(value, digits + (value < 1 ? 1 : 0) - ret.indexof('.')).tostring(); return ret; } where digits static constant; make variable, project in particular makes little sense so. still, seems overly ...