How to use Bitxor for Double Numbers?

拟墨画扇 提交于 2019-12-02 13:06:05

The functions You are looking for might be: int8(number), int16(number), uint32(number) Any of them will convert Double to an Integer, but You must pick the best one for the result You want to achieve. Remember that You cannot cast from Double to Integer without rounding the number.

If I understood You correcly, You could create a function that would simply remove the "comma" from the Double number by multiplying your starting value by 2^n and then casting it to Integer using any of the functions mentioned earlier, performing whatever you want and then returning comma to its original position by dividing the number by 2^n

Multiplying the starting value by 2^n is a hack that will decrease the rounding error. The perfect value for n would be the number of digits after the comma if this number is relatively small.

Please also specify, why are You trying to do this? This doesn't seem to be the optimal solution.

You can just cast to an integer:

a = 1.003

int8(a)

ans =

1

That gives you an 8 bit signed integer, you can also get other size i.e. int16 or else unsigned i.e. uint8 depending on what you want to do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!