Skip to content

Commit 11fc5b0

Browse files
committed
fix .to.hex() outputting decimal hex values (fixes #25)
1 parent 105ecfa commit 11fc5b0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,6 @@ function clamp(num, min, max) {
237237
}
238238

239239
function hexDouble(num) {
240-
var str = num.toString(16).toUpperCase();
240+
var str = Math.round(num).toString(16).toUpperCase();
241241
return (str.length < 2) ? '0' + str : str;
242242
}

test/basic.js

+3
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,6 @@ assert.equal(string.to.keyword([100, 255, 0]), undefined);
185185
// Make sure .get() doesn't return object prototype values (regression test, #44)
186186
Object.keys(Object.getOwnPropertyDescriptors(Object.prototype))
187187
.map(property => assert.deepStrictEqual([property, string.get(property)], [property, null]));
188+
189+
// Make sure writing decimal values as hex doesn't cause bizarre output (regression test, #25)
190+
assert.equal(string.to.hex([44.2, 83.8, 44]), '#2C542C');

0 commit comments

Comments
 (0)