I am querying a database field that returns a money value, I am assigning this to a string but it is adding extra 00 on the end.
e.g. Query returns 30.00
I am currently developing a boatdock web system, using VS 2013 Community edition. I was trying to work out how to output a currency value into a textbox.
The method that I used was
fieldName.Text = decimalValue.ToString("c");
It works perfectly.
In SQLServer a money data type is the equivalent of a decimal with 4 decimal places of precision. I would assume this is precision is conserved when the decimal is converted to a string. The best option would be to always use a format string eg "#,##0.00" when doing the conversion.
I'd use something like
string value = ReturnValue.ToString("0.00");
This uses the ToString overload that accepts a format string. The above format string "0.00" specifies two decimal places.
My recommendation is to convert it to Decimal firstly. I'd use something like this:
string value = (Convert.ToDecimal(ReturnValue)).ToString("0,0.00");