C# Int to Decimal Conversion - 在指定位置插入小数点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10044603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Int to Decimal Conversion - Insert decimal point at specified location
提问by Baxter
I have the following int 7122960
I need to convert it to 71229.60
我有以下 int 7122960
我需要将其转换为 71229.60
Any ideas on how to convert the int into a decimal and insert the decimal point in the correct location?
关于如何将 int 转换为小数并将小数点插入正确位置的任何想法?
采纳答案by Bala R
int i = 7122960;
decimal d = (decimal)i / 100;
回答by yoozer8
Simple math.
简单的数学。
double result = ((double)number) / 100.0;
Although you may want to use decimalrather than double: decimal vs double! - Which one should I use and when?
尽管您可能想要使用decimal而不是double:十进制与双精度!- 我应该在什么时候使用哪一个?
回答by dennis
Declare it as a decimalwhich uses the intvariable and divide this by 100
将其声明为decimal使用int变量并将其除以 100 的 a
int number = 700
decimal correctNumber = (decimal)number / 100;
Edit: Bala was faster with his reaction
编辑:巴拉的反应更快

