使用十进制将 int 转换为 BigDecimal - Java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35758179/
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
Convert int to BigDecimal with decimal - Java
提问by cakes88
I'm having a hard time figuring out how to convert this. Here is what I want:
我很难弄清楚如何转换它。这是我想要的:
int i = 5900;
BigDecimal bD = new BigDecimal(i);
I need bD to be 59.00 but I can't figure out how to get this result. All I've been able to get is 5900 as type BigDecimal. Any suggestion would help, thanks.
我需要 bD 为 59.00,但我不知道如何得到这个结果。我所能得到的只是 BigDecimal 类型的 5900。任何建议都会有所帮助,谢谢。
采纳答案by Louis Wasserman
You haven't been very specific about the semantics you want, but it looks like
你对你想要的语义不是很具体,但看起来像
BigDecimal.valueOf(i).movePointLeft(2)
does what you want.
做你想做的。