I’m trying to to format a number using the DecimalFormat but the problem that I didn’t get the expected result. Here is the problem: I have this number: 1439131519 and I want to print only the five first digits but with a comma after 4 digits like this: 1439,1. I have tried to use DecimalFormat but it didn’t work. I
Tag: rounding
How to round a BigDecimal before the decimal?
I have a BigDecimal like this var a = new BigDecimal(“1234.56”) and I want to round it to commercially to two places before the decimal, so that I get something equivalent to var b = new BigDecimal(“1200.00”) so that (new BigDecimal(“1200.00”)).equals(b). My best approach currently is var b = new BigDecimal(a.setScale(-2, RoundingMode.HALF_UP).toPlainString()).setScale(2); but I’m unsure if this is the right
How to make BigDecimal division more precise
I’m having an issue with BigDecimals, the simplified idea is to: define a value for the total split the total in 3 parts defined by weights, these weights are 3 double values that add up to 100.0 sum up the parts the sum should be close to the total, the error should be at most 0.00000001 Here’s the failing test:
Java: Round an Integer to an element of a given List
Supose i have a List of Integers: ints = {0,10,20,30,40,50} and an input value input = 17 How do i get the closest integer of the list to the given input? For my example it would be 20. Or to restate …
Rounding to 0.05 taxes what am I doing wrong?
I’m super stuck on this problem and I don’t know where the math is going wrong. here goes.. Calculate the tax on these 2 products. tax should be rounded to the nearest 0.05. product_ONE price = $47.50 with a tax of 15%—answer should be $54.65; 47.50 * 15 / 100 = 7.125 7.125 / 0.05 = 142.5 -> rounded you
Rounding Up To The Nearest Hundred
I came to a part in my java program where I need to round up to the nearest hundred and thought that there was probably some way to do it but I guess not. So I searched the net for examples or any answers and I’ve yet to find any since all examples appear to be to the nearest hundred.