Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Js Numbers - fractions


I want this:

In website have var number = 0.33 and I want var second = fractions of variable 'number', and if "number" fractions change : second will change.

But how?

like image 451
Radi Cho Avatar asked Sep 12 '15 12:09

Radi Cho


People also ask

What is Number () in JavaScript?

Javascript Number() Function object: This parameter holds the objects that will be converted any type of javascript variable to number type. Return Values: Number() function returns the number format for any type of javascript variable. Example 2: Not a number is returned by the compiler.

What is float in JavaScript?

JavaScript numbers are always stored as double precision floating point numbers, following the international IEEE 754 standard. This format stores numbers in 64 bits, where the number (the fraction) is stored in bits 0 to 51, the exponent in bits 52 to 62, and the sign in bit 63: Value (aka Fraction/Mantissa)


1 Answers

You can use Erik Garrison's fraction.js library to do that and more fractional operations.

var second = new Fraction(.033);
console.log(second.numerator + '/' + second.denominator);
like image 152
Akhilesh Singh Avatar answered Oct 24 '22 04:10

Akhilesh Singh