How to display double or float data with 2 decimal places in Java?

There are multiple approaches to display double or float data with 2 decimal places in Java. The post presents a way using DecimalFormat.

output:
31.24

If you want to format any double number to currency supported format with 2 decimal places, (for example, change 4 to 4.00, 45.5 to 45.50), we can implement it as

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">