You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.5 KiB

4 years ago
  1. # num2fraction
  2. [![Build Status](https://travis-ci.org/yisibl/num2fraction.svg)](https://travis-ci.org/yisibl/num2fraction)
  3. [![NPM Downloads](https://img.shields.io/npm/dm/num2fraction.svg?style=flat)](https://www.npmjs.com/package/num2fraction)
  4. [![NPM Version](http://img.shields.io/npm/v/num2fraction.svg?style=flat)](https://www.npmjs.com/package/num2fraction)
  5. [![License](https://img.shields.io/npm/l/num2fraction.svg?style=flat)](http://opensource.org/licenses/MIT)
  6. > Converting Number to Fraction with Node.js.
  7. ## Installation
  8. ```console
  9. npm install num2fraction
  10. ```
  11. ## Usage
  12. ```js
  13. var π = Math.PI
  14. var n2f = require('num2fraction')
  15. console.log(n2f(0)) // => 0
  16. console.log(n2f(.2)) // => 1/5
  17. console.log(n2f(1.1)) // => 11/10
  18. console.log(n2f(1.2)) // => 6/5
  19. console.log(n2f(1.3)) // => 13/10
  20. console.log(n2f(1.4)) // => 7/5
  21. console.log(n2f(1.5)) // => 3/2
  22. console.log(n2f(2)) // => 2/1
  23. console.log(n2f(2.1)) // => 21/10
  24. console.log(n2f(3)) // => 3/1
  25. console.log(n2f(2.555)) // => 511/200
  26. console.log(n2f(8.36)) // => 209/25
  27. console.log(n2f('3em')) // => 3/1
  28. console.log(n2f('1.5px')) // => 3/2
  29. console.log(n2f(7 / 9) // => 7/9
  30. console.log(n2f(8 / 9) // => 8/9
  31. console.log(n2f(512 / 999) // => 512/999
  32. console.log(n2f((2 * π / 3) / π) // => 2/3
  33. console.log(n2f((8 * 5) / (4 / 2)) // => 20/1
  34. ```
  35. ## Example
  36. Opera [old versions](http://www.opera.com/docs/specs/presto28/css/o-vendor/) support the non-standard `-o-min-device-pixel-ratio` or `-o-max-device-pixel-ratio` in CSS media queries.
  37. ```css
  38. @media
  39. only screen and (-webkit-min-device-pixel-ratio: 2),
  40. only screen and ( min--moz-device-pixel-ratio: 2),
  41. only screen and ( -o-min-device-pixel-ratio: 2/1), /* Opera */
  42. only screen and ( min-device-pixel-ratio: 2),
  43. only screen and ( min-resolution: 192dpi), /* fallback */
  44. only screen and ( min-resolution: 2dppx) {
  45. }
  46. ```
  47. ## Changelog
  48. ### v1.2.2
  49. * \+ Remove: Debug log message.
  50. ### v1.2.1
  51. * \+ Fix: 0 must be converted to a string.
  52. ### v1.2.0
  53. * \+ Fix: Accomodate rounding errors. (by @jamestalmage)
  54. * \+ Fix: The negative sign should be on numerator. (by @jamestalmage)
  55. ### v1.1.0
  56. * \+ Use more precise (not fixed) precision factor for the calculation
  57. ### v1.0.1
  58. * \- Remove "ci.testling.com"
  59. ### V1.0.0
  60. > First release.
  61. ## License
  62. [MIT](LICENSE)