27

I have the following int 7122960
I need to convert it to 71229.60

Any ideas on how to convert the int into a decimal and insert the decimal point in the correct location?

4

3 回答 3

63
int i = 7122960;
decimal d = (decimal)i / 100;
于 2012-04-06T14:06:31.950 回答
5

简单的数学。

double result = ((double)number) / 100.0;

尽管您可能想使用decimal而不是double十进制与双精度!- 我应该使用哪一个以及何时使用?

于 2012-04-06T14:06:12.763 回答
4

将其声明为decimal使用int变量并将其除以 100

int number = 700
decimal correctNumber = (decimal)number / 100;

编辑:巴拉的反应更快

于 2012-04-06T14:08:24.127 回答