Java floating point math - (conversion for feet/meters)

前端 未结 5 472
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 16:36

Pretty basic question I think - I\'m performing this function:

private double convertMetersToFeet(double meters)
{
  //function converts Feet to Meters.
             


        
5条回答
  •  清酒与你
    2021-01-20 17:12

    If you need precise calculations, use BigDecimal instead of float. If you just want to truncate on printing, use DecimalFormat.

    DecimalFormat df = new DecimalFormat ("0.00");
    System.out.println(df.format(convertMetersToFeet(101)));
    

提交回复
热议问题