Skip to content
Advertisement

Tag: rounding

How to round and scale a number using DecimalFormat

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

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

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.

Advertisement