a user submits a buy request: 0.0104 BTC at a rate of 345.92 EUR
config:
var mode = RoundingMode.HALF_EVEN();
var satoshi = new BigDecimal("100000000");
user input:
var btc_b = new BigDecimal("0.0104");
var rate_b = new BigDecimal("345.92");
convert amount to smallest unit:
var btc_s = btc_b.multiply(satoshi);
btc * rate = spend:
var eur_s = btc_s.multiply(rate_b).setScale(0,mode);
console.log(eur_s.longValue());
output: 359756800
eur / smallest unit:
var eur_b = eur_s.divide(satoshi, 8, mode);
console.log(eur_b.longValue());
output: 3.597568
but since eur has only 2 decimals:
console.log(eur_b.setScale(2,mode).longValue());
output: 3.6
i assume the user must spend 3.6 EUR for 0.0104 BTC at a rate of 345.92 EUR
here's a fiddle: jsfiddle.net/nvkja98c/
please correct me if i'm wrong!