简体   繁体   English

货币格式的十进制返回

[英]Decimal return in currency format

is it possible to return decimal from web service with value 0C instead of 0M.是否可以从 Web 服务返回十进制值 0C 而不是 0M。 return type must be decimal so converting to currency string option doesnt work.返回类型必须是十进制,因此转换为货币字符串选项不起作用。

decimal return value is 0M but in response it is shown as <Money>0.0000</Money> value must be in currency format ie 0.00十进制返回值为0M但作为响应,它显示为<Money>0.0000</Money>值必须采用货币格式,即0.00

Maybe some DataAnotation would help?也许一些 DataAnotation 会有所帮助?

I know two solutions to solve this problem.我知道解决这个问题的两种解决方案。

One

Return strings:返回字符串:

string money = yourValue.ToString("0.00");

Two

Use Round :使用Round

decimal money = Math.Round(yourValue, 2);

Parsed已解析

It will always add .00 to integer values.它总是将.00添加到整数值。

decimal money = decimal.Parse(yourvalue.ToString("0.00"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM