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

how do i set a math context? #1

Open
boxxxie opened this issue Dec 28, 2011 · 6 comments
Open

how do i set a math context? #1

boxxxie opened this issue Dec 28, 2011 · 6 comments

Comments

@boxxxie
Copy link

boxxxie commented Dec 28, 2011

it's from java.math, but i need to use it in the bigdecimal class.

var currencyContext = new bigdecimal.MathContext(2)
TypeError: Object 2 has no method 'gC'
@boxxxie
Copy link
Author

boxxxie commented Dec 28, 2011

enum contexts are giving me problems too.

var currencyContext = bigdecimal.MathContext.DECIMAL128;
undefined
bigdecimal.BigDecimal("123",currencyContext).toString()
java.lang.RuntimeException: Unknown call signature for obj = new java.math.BigDecimal: string function

@jhs
Copy link
Member

jhs commented Dec 29, 2011

Interesting. Which browser or Javascript engine are you using? Thanks!

@boxxxie
Copy link
Author

boxxxie commented Dec 29, 2011

Chrome. On ubuntu 11.10
I'll test on FireFox tomorrow.
I found a work around and ill post it tomorrow.

@fsateler
Copy link

fsateler commented May 4, 2012

I'm having the same issue, node on linux

> process.versions
{ node: '0.6.16',
  v8: '3.8.9.16',
  ares: '1.7.5',
  uv: '0.6',
  openssl: '1.0.1b' }

@chrismeyersfsu
Copy link

Has anyone solution / workaround been found ?

@MikeMcl
Copy link

MikeMcl commented Mar 12, 2014

@chrismeyersfsu

Oddly, MathContext only seems to accept strings:

var x = new BigDecimal('5');
var y = new BigDecimal('3');   

var mc = new MathContext('precision=5 roundingMode=HALF_UP');
x.divide( y, mc );    // '1.6667'    

// A precision of 16 digits and rounding mode HALF_EVEN.
// Notice that DECIMAL64 is a function.
x.divide( y, MathContext.DECIMAL64() );    // 1.666666666666667    

// Two decimal places and rounding mode ROUND_HALF_UP.
x.divide( y, 2, 4 );    // '1.67'

// DOWN is a function, but ROUND_DOWN isn't.
x.divide( y, 6, RoundingMode.DOWN() );    // '1.666666'    
x.divide( y, 6, BigDecimal.ROUND_DOWN );    // '1.666666'

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

5 participants