[英]How to convert number into decimal with shifted decimal separator?
I have to import a file that have an amount in the following format:我必须导入具有以下格式金额的文件:
Id Amount
101 123456
102 456789
I'm using FileHelpers
library with [FieldConverter(ConverterKind.Decimal)]
attribute but it converts the amount into this:我正在使用带有[FieldConverter(ConverterKind.Decimal)]
属性的FileHelpers
库,但它将数量转换为:
12356 --> $123456
I want it to apply last two digits to the decimals.我希望它将最后两位数字应用于小数。 I want it to look like this:我希望它看起来像这样:
123456 --> $1234.56
456789 --> $4567.89
Any ideas?有任何想法吗? Thanks.谢谢。
UPDATE: I came up with my own solution.更新:我想出了我自己的解决方案。 I've created a separate field called Amount
that calculates the payment amount based on the the amount provided in file, which is parsed into the private variable called AmountRaw
.我创建了一个名为Amount
的单独字段,它根据文件中提供的Amount
计算付款金额,该文件被解析为名为AmountRaw
的私有变量。
[DelimitedRecord(",")]
public class PaymentFileRecord
{
public int PaymentId;
[FieldConverter(ConverterKind.Date, "yyyyMMdd")]
public DateTime PaymentDate;
[FieldConverter(ConverterKind.Decimal)]
private decimal AmountRaw;
public decimal Amount
{
get { return AmountRaw / 100; }
}
}
试试这个:将你收到的数字除以 100。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.