Browse files

Fixed bytetohex function in CPColor to make conversion to hex more ac…

…curate
  • Loading branch information...
1 parent 0062caa commit c135d4a942172ebad3597d5a1f0a7354d1df6c6d Sheena Pakanati committed May 26, 2010
Showing with 4 additions and 4 deletions.
  1. +4 −4 AppKit/CPColor.j
View
8 AppKit/CPColor.j
@@ -734,11 +734,11 @@ function rgbToHex(r,g,b) {
return byteToHex(r) + byteToHex(g) + byteToHex(b);
}
-function byteToHex(n) {
+function byteToHex(n) {
if (!n || isNaN(n)) return "00";
- n = ROUND(MIN(255,MAX(0,256*n)));
- return hexCharacters.charAt((n - n % 16) / 16) +
- hexCharacters.charAt(n % 16);
+
+ var m = MIN(255, MAX(0, ROUND(255 * n)));
+ return (m > 16 ? "" : "0") + m.toString(16);
}
// Toll-Free bridge CPColor to CGColor.

0 comments on commit c135d4a

Please sign in to comment.