Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comperation between two numbers, getting wrong #211

Open
dht20 opened this issue May 12, 2024 · 1 comment
Open

comperation between two numbers, getting wrong #211

dht20 opened this issue May 12, 2024 · 1 comment

Comments

@dht20
Copy link

dht20 commented May 12, 2024

i build a function
`

function whoisbiggerxxx(a1, b1) {
	a = new Big(a1);
	b = new Big(b1);
	/* var a  = a1.split(".").pop().substring(0,10);
	var b  = b1.split(".").pop().substring(0,10);
	if ( first10Decimals  == second10Decimals )
	{
	   //they are equal
	} */
	if(a>b){
		console.log("a>b", a1+" > "+b1);
	}
	else if (a<b){
		console.log("a<b", a1+" < "+b1);
	}
	else if (a==b){
		console.log("a=b", a1+" = "+b1);
	}
}
	whoisbiggerxxx("1", "2");
	whoisbiggerxxx("1.1", "2");
	whoisbiggerxxx("110", "2.1");
	whoisbiggerxxx("1", "0.2");
	whoisbiggerxxx("4.64665558835226358211",  "464665558835226358.2");

`
and my test result is

a<b 1 < 2 
a<b 1.1 < 2 
a<b 110 < 2.1 // wrong
a>b 1 > 0.2 
a<b 4.64665558835226358211 < 464665558835226358.2
@nycdotnet
Copy link
Contributor

Welcome to GitHub. Big doesn’t work with < or > since there is no way to do operator overloading with JavaScript. Take a look at the documentation which is linked off the readme. It explains how to do greater than and less than comparisons with Big.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants