Override decimal ToString() method

Posted by Jimbo on Stack Overflow See other posts from Stack Overflow or by Jimbo
Published on 2011-10-04T12:59:14Z Indexed on 2011/11/28 17:52 UTC
Read the original article Hit count: 155

Filed under:
|
|
|

I have a decimal datatype with a precision of (18, 8) in my database and even if its value is simply 14.765 it will still get displayed as 14.76500000 when I use Response.Write to return its value into a webpage.

Is it possible to override its default ToString method to return the number in the format #,###,##0.######## so that it only displays relevant decimal places?

UPDATE

I'm assuming that when one outputs number on a page like <%= item.price %> (where item.price is a number) that the number's ToString method is being called?

I'm trying to avoid having to change every instance where the value is displayed by defaulting the ToString() format somehow.

© Stack Overflow or respective owner

Related posts about c#

Related posts about override