I want to shorten a number to the first significant digit that is not 0. The digits behind should be rounded.
Examples:
0.001 -> 0.001 0.00367 -&g
var value = 0.000000564; int cnt = 0; bool hitNum = false; var tempVal = value; while (!hitNum) { if(tempVal > 1) { hitNum = true; } else { tempVal *= 10; cnt++; } } var newValue = (decimal)Math.Round(value, cnt);