Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
Cómo expresar "1.275" a "1.28" con formato decimal en Java
DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setRoundingMode(RoundingMode.HALF_UP); decimalFormat.applyPattern(".00"); System.out.print(decimalFormat.format(63.275)); // output : 63.27 System.out.print(decimalFormat.format(64.275)); // output : 64.28

¿Por qué son diferentes?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

El valor de 63,275 se registra en la computadora como 63,27499999999999857891452847979962825775146484375. Según el documento de la API de Java " https://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html#HALF_UP " Se comporta como RoundingMode.UP si la fracción descartada es ≥ 0,5; de lo contrario, se comporta como RoundingMode.DOWN. asi que ,

 63.27499999999999857891452847979962825775146484375 ~ 63.27 64.275000000000005684341886080801486968994140625 ~ 64.28
over 4 years ago · Santiago Trujillo Report

0

public static double roundByPlace(double number, int scale){ BigDecimal bigDecimal = BigDecimal.valueOf(number); String pattern = "0."; for(int i = 0; i<scale; i++){ pattern = pattern+"0"; } DecimalFormat decimalFormat = new DecimalFormat(pattern); decimalFormat.setRoundingMode(RoundingMode.HALF_UP); double result = Double.parseDouble(decimalFormat.format(bigDecimal)); return result; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!