如何将数字的后3位转换为0 [英] How to convert last 3 digits of number into 0

查看:147
本文介绍了如何将数字的后3位转换为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数字的后3位转换为0

How to convert last 3 digits of number into 0

示例3444678至3444000

example 3444678 to 3444000

我可以喜欢

(int)(3444678/1000)* 1000 = 3444000

(int)(3444678/1000) * 1000= 3444000

但是除法和乘法可能会花费很大……

But division and multiplication could be costly...

还有其他解决方案吗??

Any other solution????

推荐答案

您可以尝试

n - (n % 1000)

,但是模运算符可能和除法一样昂贵.无论如何,这听起来像是微优化.这真的是您的瓶颈吗?

but the modulus operator might be as costly as a division. In any case, this sounds an awful lot like a micro-optimization. Is this really your bottleneck?

这篇关于如何将数字的后3位转换为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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