3

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 JavaScript jsyk.

McKayla
  • 6,879
  • 5
  • 36
  • 48

2 Answers2

1

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

Jeremiah Willcock
  • 30,161
  • 7
  • 76
  • 78
0

You can just do

28.5.toString(16);

Which correctly yields 1c.8

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214