Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>as you want the decimal to be displayed as sign and not as a lot of 0's you could as well do something like:</p> <pre><code>class Program { static void Main(string[] args) { //these are your "unit precedessors" char[] exponentsbig = new char[] {' ', 'k', 'M', 'G', 'T', 'P', 'E' }; char[] exponentssmall = new char[] { ' ', 'm', 'µ', 'n', 'p', 'a', 'f' }; //some example numbers long[] numbersBig = new long[] { 3000, 3003, 30000, 300000, 300003, 1594900000000000 }; double[] numbersSmall = new double[] { 0.0002, 0.245, 0.245003, 0.000004578 }; //some helper vars int counter = 0; bool edited = false; //let's have a look at what we produce;) string output = ""; //Big numbers incoming!! for (int i = 0; i &lt; numbersBig.Length; i++) { counter=0; double myNumber = Convert.ToDouble(numbersBig[i]); do { edited = false; //something to prevent unnecessary unit-adding and making sure you still divide by 1000 if (myNumber/1000&gt;1 ) { counter++; myNumber /= 1000; edited = true; } } while (edited); output += numbersBig[i] + " " + myNumber + exponentsbig[counter] + "\n"; } //small numbers incoming!! for (int i = 0; i &lt; numbersSmall.Length; i++) { counter = 0; double myNumber = numbersSmall[i]; do { edited = false; //this will go to 3 digits after comma. you can make the compared smaller //to be more exact after the comma, but keep in mind you lose steps then if (myNumber &lt; 1) { counter++; myNumber *= 1000; edited = true; } } while (edited); output += numbersSmall[i] + " " + myNumber + exponentssmall[counter] + "\n"; } //see what we did Console.Write(output); Console.ReadKey(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload