gpt4 book ai didi

java - 整数乘以 0.5 时四舍五入

转载 作者:行者123 更新时间:2023-11-29 03:07:28 26 4
gpt4 key购买 nike

<分区>

有没有办法在 java 中自动舍入一个值?

例如:

//generate a random integer value
int randomVal = RandomHelper.nextIntFromTo(1, otherVal);

/* then divide the integer value in half... the error I am getting is that its a double, probably
because the number generated isn't an even number, but I NEED it to be an integer. Can I round up?*/
int value = randomVal * 0.5;

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com