C# Currency to string

后端 未结 10 2849
旧巷少年郎
旧巷少年郎 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:32

    Do you want your string formatted using a currency character?

    If so...

    decimal m = 3.4;
    
    string s = string.Format("{0:c}", m);
    
    // s will be £3.40, $3.40, etc depending on your locale settings
    

提交回复
热议问题