Rounding float/decimal to 3 decimal places exactly?

You appear to want to round down to FOUR decimal places instead of rounding half up.

You appear to want to round down to FOUR decimal places instead of rounding half up. Double d = 0.08095238095238096; d = (long) (d * 10000) / 10000.0; or d = Math. Floor(d * 10000) / 10000.0; I assume you mean you want d = 0.0809 instead of 0.809.

Perhaps you are thinking of 3 significant digits which is a harder problem. Its best to use double or BigDecimal instead of float unless you have a very good reason. BTW: It is useful to have a clear idea of what you want, otherwise its going to be much harder to find it.

;).

Your problem is your original number is wrong. If you need to get 0.809 you'll need to start with 0.8095238095238096 (not 0.08095238095238096 as you have).

Perhaps this is a comment rather than an answer. ;) – Peter Lawrey Nov 11 at 12:05 To be honest, I think ridicule is the least this question deserves if he can't even take the time to make sure the simplest part of his question is correct, especially when people like you take the time to give a well thought-out answer. – Bohemian Nov 11 at 12:08 Not having a clear idea of what the OP wanted is why I suspect he had so much trouble searching for a solution.

– Peter Lawrey Nov 11 at 12:10 The numbers were examples from a book, generally following a book you expect them to be correct. In future I will check these values... – Lunar Nov 11 at 12:18.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions