将double转换为int(java) [英] Convert double to int (java)
本文介绍了将double转换为int(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个程序来模拟太阳系。
I'm trying to make a program to simulate the solar system.
for(int i=0;i<1000;i++) {
double X=(160*Math.cos((2*PI*i)/365));
double Y=(160*Math.sin((2*PI*i)/365));
posX=Math.round(X);
posY=Math.round(Y);
cadre.repaint();
sleep(200);
}
f.setVisible(false);
为了让我的行星转过身来,我有一个公式;问题是我有一个双数字与这个公式,我不能让他成为一个int(我尝试了地板(X),Math.round(X),不工作(错误:不兼容的类型:可能的损失从long转换为int)
To make my planets turning around the sun, I have a formula; the problem is that i have a double number with this formula, and i can't make him become an int (i tried floor(X), Math.round(X), doesn't work (error : incompatible types : possible lossy conversion from long to int)
[]
你会看到它不是真正的java,但他的工作是Java(这是一些Javascool),所以你的建议可能适用于我! p>
You'll see that it is not really java but he works as Java (it's some Javascool), so your advices will probably work for me!
推荐答案
添加转换为int,如:
Add cast to int like:
posX = (int) Math.round(X);
这篇关于将double转换为int(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文