C# Currency to string

后端 未结 10 2820
旧巷少年郎
旧巷少年郎 2021-02-19 10:52

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

10条回答
  •  天涯浪人
    2021-02-19 11:33

    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.

提交回复
热议问题