如何将Integer值转换为十进制值? [英] How can i convert Integer value to decimal value?

查看:135
本文介绍了如何将Integer值转换为十进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个整数值:

Integer value = 56472201;

价值可能是正数还是负数。

Where the value could be positive or negative.

当我将值除以1000000时,我希望此结果的格式为 56.472201 ,但它只给出了商数。如何获得商和余数值?

When I divide the value by 1000000, I want this result in the form 56.472201 but instead it gives me just the quotient. How am I able to get both the quotient and remainder values?

推荐答案

将其转换为浮动然后执行:

cast it to float and then do it:

int i = 56472201;

float j = ((float) i)/1000000.0

编辑:由于精度(在您的情况下需要),请使用double。同样如Konrad Rudolph指出的那样,不需要显式投射:

Due to precision(needed in your case), use double. Also as pointed by Konrad Rudolph, no need for explicit casting:

double j = i / 1000000.0;

这篇关于如何将Integer值转换为十进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆