The Java backend retains two decimal places

Source: Internet
Author: User

The Java backend retains two decimal places


1. (double) (Math.Round (sd3*10000)/10000.0);

this keeps the 4-bit

( Double) (Math.Round (sd3*100)/100.0);

this keeps the 2 bits.



2. Another approach
import Java.text.DecimalFormat;

DecimalFormat df2 = new DecimalFormat ("###.00");

DecimalFormat df2 = new DecimalFormat ("###.000");

System.out.println (Df2.format (Doube_var));

The first one is 2 bits and the second is 3 bits.

3 new JDK
String.Format ("%10.2f%%", Doube_var);


This article is from the "beautiful Dē‖java Question" blog, please be sure to keep this source http://teny32.blog.51cto.com/8027509/1592656

The Java backend retains two decimal places

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.