开发者

Converting fractions into hexadecimal

开发者 https://www.devze.com 2023-02-11 07:38 出处:网络
Say you had a number (28.5) and you needed to convert it into hexadecimal. 28 would be 1C, and 29 would be 1D, but what would 28.5 be?

Say you had a number (28.5) and you needed to convert it into hexadecimal.

28 would be 1C, and 29 would be 1D, but what would 28.5 be?

Could you even convert that?

I'm asking this because I'm making a converter in Ja开发者_如何转开发vaScript jsyk.


Use n.toString(16). I tested it, and (at least on Safari) it handles fractions correctly.


You can just do

28.5.toString(16);

Which correctly yields 1c.8

0

精彩评论

暂无评论...
验证码 换一张
取 消