货币值字符串 [英] string to Monetary values
本文介绍了货币值字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我需要使用前导将货币值格式化为s9(6)v99格式
零.例如:
字符串->双重
002000-> 20.00
002056-> 20.56
在C#中
怎么回事?
谢谢&问候
1206
Hi
I need to format monetary values to s9(6)v99 format with leading
zeroes. For example:
string -> Double
002000 -> 20.00
002056 -> 20.56
in c#
what is the way ?
Thanks & Regards
1206
推荐答案
应该很简单:
Should be pretty easy:
decimal result = decimal.Parse("002056")/100m;
.NET中的数字类型具有Parse()
和TryParse()
方法来处理转换.如果可以保证使用s9(6)99格式,则可以使用Parse()
.
使用m后缀表示十进制类型.十进制为您提供币种所需的精度.
干杯.
The numeric types in .NET have Parse()
and TryParse()
methods to handle the conversion. If you''re guaranteed the s9(6)99 format, you can likely get away with Parse()
.
Use the m suffix to denote decimal types. Decimal gives you the precision you need for currency.
Cheers.
这篇关于货币值字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文