gpt4 book ai didi

c# - 我如何将 double 值转换为最接近的整数值?

转载 作者:IT王子 更新时间:2023-10-29 03:33:01 27 4
gpt4 key购买 nike

如何将 double 转换为最接近的 int?

最佳答案

double d = 1.234;
int i = Convert.ToInt32(d);

Reference

像这样处理舍入:

rounded to the nearest 32-bit signed integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is converted to 4, and 5.5 is converted to 6.

关于c# - 我如何将 double 值转换为最接近的整数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/633335/

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