简体   繁体   English

整数下限至最接近的10,000

[英]Floor of integer to the nearest 10,000

If possible can anyone advise the best way to get the floor of an integer eg 388,000 should always return the floor of 380,000. 如果可能的话,任何人都可以建议获得整数下限的最佳方法,例如388,000应该始终返回380,000的下限。

Thats to say the floor should always be rounded down to 10,000. 就是说,下限应始终四舍五入到10,000。

I saw math.floor(300.16): 我看到了math.floor(300.16):

Result: 结果:

300.0 300.0

However this function only applies the floor to the decimal places. 但是,此功能仅将底数应用于小数位。

All help is greatly appreciated 非常感谢所有帮助

Thanks 谢谢

you can first subtract 5000 from your number and then round to 4 place before the decimal points: 您可以先从数字中减去5000,然后四舍五入到小数点前4位:

round(388000-5000, -4)
380000

round(383000-5000, -4)
380000

Or to use floor function with a trick: 或通过以下方式使用发言权功能:

math.floor(388000/10000)*10000
380000

I would divide the given integer by 10,000.0 (with type cast to float), then floor and then multiply by 10.000 (with type cast to integer). 我将给定的整数除以10,000.0(类型转换为浮点型),然后求和,然后乘以10.000(类型转换为整数)。 Should do the job. 应该做的工作。

Maybe your language cuts the decimals when you divide integers, than you may spare the casting and flooring and just divide and multiply. 也许在除以整数时,您的语言会减少小数点,然后您就可以省掉转换和底线,而只是除以乘法。

I'm assuming you want to perform this operation on a pandas series, given this question is tagged with pandas . 考虑到这个问题是用pandas标记的,我假设您想对pandas系列执行此操作。

UPDATED: Thanks to GZ0 更新:感谢GZ0

s = s // 10000 * 10000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM