Follow-up to how to get an Integer as result
I asked a question How to get an Integer as result?
The suggested solution with decimalFormat
works, but my problem is that I want my data not only to be presented as ##.0
but to be like this, because in the end of my program I use them. So I want to be exactly in that开发者_C百科 type; otherwise I get the wrong final number. Any ideas?
EDIT:
let me be more specific. i get 12,344 from my first calc, 14,4566 from my second and 18,5644 from my third.that makes a sum 45.365.Now,if i do then 12,3 , 14,4 and 18,5 the sum is 45.2...thats the point of my answer.i want to have 45.365 at the end and not 45.2
The problem seems to be a design issue with your app.
On the one hand, you want to display the results to the user with 1 digit after the decimal point.
In the other hand, you actually want to keep the extra precision and use it for follow-up calculations.
I would argue that this is a poor user interface model. IMO, the numbers that the user sees should be the numbers that go into the calculations. This means you should either:
- show the user more digits after the DP in the first place (or at least give a visual indication that there are more digits), or
- do the calculations using the rounded / truncated values ... as displayed to the user.
Once you have figured out a consistent user interface model, the required implementation approach should be much clearer to you.
精彩评论