Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This meets the example given but POORLY. (I THINK)</p> <pre><code>myDecimal.ToString("#.######") </code></pre> <p>What other requirements are there? Are you going to manipulate the values and show the manipulated values to this number of decimals?</p> <p>Alternate answer involves recursiveness, like so:</p> <pre><code> //use like so: myTextbox.Text = RemoveTrailingZeroes( myDecimal.ToString() ); private string RemoveTrailingZeroes(string input) { if ( input.Contains( "." ) &amp;&amp; input.Substring( input.Length - 1 ) == "0" ) { //test the last character == "0" return RemoveTrailingZeroes( input.Substring( 0, input.Length - 2 ) ) //drop the last character and recurse again } return input; //else return the original string } </code></pre> <p>And if you wanted an extension method, then this is an option</p> <pre><code> //use like so: myTextbox.Text = myDecimal.ToString().RemoveTrailingZeroes(); private string RemoveTrailingZeroes(this string input) { if ( input.Contains( "." ) &amp;&amp; input.Substring( input.Length - 1 ) == "0" ) { //test the last character == "0" return RemoveTrailingZeroes( input.Substring( 0, input.Length - 2 ) ) //drop the last character and recurse again } return input; //else return the original string } </code></pre> <p>Added <code>input.Contains( "." ) &amp;&amp;</code> per comment from Jon Skeet, but bear in mind this is going to make this incredibly slow. If you know that you'll always have a decimal and no case like <code>myDecimal = 6000;</code> then you could drop that test, or you could make this into a class and have several private methods based on whether the input contained a decimal, etc. I was going for simplest and "it works" instead of <code>Enterprise FizzBuzz</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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