从双精度到浮点的可能有损转换 [英] possible lossy conversion from double to float
本文介绍了从双精度到浮点的可能有损转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图分裂,并且不断收到此错误?
i am trying to get to divide and i keep getting this error ?
等级错误;不兼容的类型;可能会从双精度转换为浮点型?
gradle error; incompatible types; possible lossy conversion from double to float?
protected World world;
protected TiledMap map;
protected TiledMapTile tile;
protected Rectangle bounds;
protected Body body;
public InteractiveTileObject(World world, TiledMap map, Rectangle bounds ){
this.world = world;
this.map = map;
this.bounds = bounds;
BodyDef bdef = new BodyDef();
FixtureDef fdef = new FixtureDef();
PolygonShape shape = new PolygonShape();
bdef.type = BodyDef.BodyType.StaticBody;
bdef.position.set((bounds.getX() + bounds.getWidth()/2)/MyGdxGame.PPM, (bounds.getY() + (bounds.getHeight() / 2)) / MyGdxGame.PPM);
body = world.createBody(bdef);
shape.setAsBox(bounds.getWidth()/2 /MyGdxGame.PPM, bounds.getHeight()/2 /MyGdxGame.PPM);
fdef.shape = shape;
body.createFixture(fdef);
}
推荐答案
如果您正在调用接受float
的方法,但又将其传递给double
,则必须将double
显式转换为float
.您可以通过在每个参数前面放置(float)
来实现此目的.例如:
If you are calling a method that accepts a float
, but you are passing it a double
, the double
must be explicitly converted to a float
. You can do this by putting (float)
in front of each argument. For example:
shape.setAsBox((float) (bounds.getWidth()/2/MyGdxGame.PPM),
(float) (bounds.getHeight()/2/MyGdxGame.PPM));
这篇关于从双精度到浮点的可能有损转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文