Int to Decimal Conversion - Insert decimal point at specified location

不羁的心 提交于 2019-12-30 07:51:42

问题


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?


回答1:


int i = 7122960;
decimal d = (decimal)i / 100;



回答2:


Simple math.

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

Although you may want to use decimal rather than double: decimal vs double! - Which one should I use and when?




回答3:


Declare it as a decimal which uses the int variable and divide this by 100

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

Edit: Bala was faster with his reaction



来源:https://stackoverflow.com/questions/10044603/int-to-decimal-conversion-insert-decimal-point-at-specified-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!