Skip to content

javascript big number calculate (js超出安全数的数值计算/js number转字符串计算)

Notifications You must be signed in to change notification settings

replace5/StringMath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

StringMath.js

A javascript library that calculate the big number(Even greater than 2^53);

parameter and return

Allow input number or string(we can call it StringNumber, number represented by a string, RegExp: /^+-\w+$/), it should be noted that the maximum number of JS security is Math.pow(2, 53) - 1, function all return string(StringNumber);

Use

plus (+)

Allow at least one parameter;

StringMath.plus(-Math.pow(2, 50), '-3234324823992349023439204', 343242.34, Math.pow(4, 23));

subtract (-)

Allow at least one parameter;

StringMath.subtract(Math.pow(2, 43), '34237489741142345487987745646784', -45415.323);

multiply (*)

Allow at least one parameter;

StringMath.multiply(Math.pow(2, 53)-1, '789749712323434', -87977.23434454);

divide (/)

Allow at least one parameter;

StringMath.DIVIDE_DECIMAL_LIMIT(default 5) to set decimal length; StringMath._divide_remain to keep the last devide remain data; StringMath._divide_int_result to keep the last devide int result;

StringMath.divide(343432432423, '123645648797456787448978797', -4545.771231);

mod (%)

Allow two parameters;

StringMath.mod('789749712323434', -4545.32);

eq (=)

Allow two parameters;

StringMath.eq('789749712323434', 789749712323434);

gt (>)

Allow two parameters;

StringMath.gt(1, '12345673234');

gte (>=)

Allow two parameters;

StringMath.gte(1, '12345673234');

lt (<)

Allow two parameters;

StringMath.lt('2137489127897541278789', 53);

lte (<=)

Allow two parameters;

StringMath.lt('2137489127897541278789', '2137489127897541278789');

max

get the maximum number of the inputs Allow at least two parameters;

StringMath.max(1, '2137489127897541278789', Math.pow(2, 32));

min

get the minimum number of the inputs Allow at least two parameters;

StringMath.min(1, '2137489127897541278789', Math.pow(2, 32));

round

Allow only one parameter;

StringMath.round('2137489127897541278789.3243434324');

ceil

Allow only one parameter;

StringMath.ceil('-2137489127897541278789.3243434324');

floor

Allow only one parameter;

StringMath.floor('2137489127897541278789.3243434324');

abs

Allow only one parameter;

StringMath.abs('-2137489127897541278789.3243434324');

toFixed

Allow two parameters, first is StringNumber, second is the decimal length youd want to keep;

StringMath.toFixed('2137489127897541278789.324567', 4); // => '2137489127897541278789.3246'

pow

Allow two parameters, first is StringNumber, second is the exponent sign(do not support decimal number);

StringMath.pow('2137489127897541278789.332', '3323');

system

Convert the decimal StringNumber to other system, like Number.prototype.toString(radix) Allow two parameters, first is StringNumber, second is the target system to convert (less than 36);

StringMath.system('2137489127897541278789', 36);

bin

decimal to binary Allow one parameter, it is the StringNumber;

StringMath.bin('2137489127897541278789');

oct

decimal to octonary Allow one parameter, it is the StringNumber;

StringMath.oct('2137489127897541278789');

hex

decimal to hexadecimal Allow one parameter, it is the StringNumber;

StringMath.hex('2137489127897541278789');

dec

Convert the other system StringNumber to decimal system, like parseFloat(Number, radix) Allow two parameters, first is StringNumber, second is the origin system (less than 36);

StringMath.dec('2137489127897541278789', 36);

About

javascript big number calculate (js超出安全数的数值计算/js number转字符串计算)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published