Skip to content

Commit

Permalink
fix .to.hex() outputting decimal hex values (fixes #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Nov 26, 2021
1 parent 105ecfa commit 11fc5b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,6 @@ function clamp(num, min, max) {
}

function hexDouble(num) {
var str = num.toString(16).toUpperCase();
var str = Math.round(num).toString(16).toUpperCase();
return (str.length < 2) ? '0' + str : str;
}
3 changes: 3 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,6 @@ assert.equal(string.to.keyword([100, 255, 0]), undefined);
// Make sure .get() doesn't return object prototype values (regression test, #44)
Object.keys(Object.getOwnPropertyDescriptors(Object.prototype))
.map(property => assert.deepStrictEqual([property, string.get(property)], [property, null]));

// Make sure writing decimal values as hex doesn't cause bizarre output (regression test, #25)
assert.equal(string.to.hex([44.2, 83.8, 44]), '#2C542C');

0 comments on commit 11fc5b0

Please sign in to comment.