如何在Pascal中将整数四舍五入至最接近的1000? [英] How can I round an integer to the nearest 1000 in Pascal?

查看:191
本文介绍了如何在Pascal中将整数四舍五入至最接近的1000?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Pascal中有一个Integer变量.我可以使用任何可能的函数将该值舍入到最接近的1000的例子,例如:

I've got a Integer variable in Pascal. Is there any possible function I can use that can round that value to the nearest 1000, for example:

RoundTo(variable, 1000);

有没有类似的东西存在?还是我应该尝试使用另一种方法?

Does anything of the sort exist? Or is there another method I should try using?

谢谢!

推荐答案

这种问题的一般解决方案是在舍入前后进行缩放,例如

The general solution for this kind of problem is to scale before and after rounding, e.g.

y = 1000 * ROUND(x / 1000);

这篇关于如何在Pascal中将整数四舍五入至最接近的1000?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆