题目描述 Given two postive integers A and B, please calculate the maximum integer C that C*B≤A, and the real number D equal to A/B. 输入格式 Two integers A and B in one line separated by a space.(A,B>0) 输出格式 Output C in one line,followed by D in one line. D
//整数相除 保留一位小数 public static String division(int a ,int b){ String result = ""; float num =(float)a/b; DecimalFormat df = new DecimalFormat("0.0"); result = df.format(num); return result; }
方式1:被除数转double后,除以除数,结果是一个double类型的数,将double结果按要求保留n位小数即可. 保留n位小数的写法 int a = 10; int b = 3; double res = new BigDecimal((double) a / b).setScale(2, RoundingMode.HALF_UP).doubleValue(); 方式2: 直接使用BigDecimal进行运算 int a = 10; int b = 3; BigDecimal bigA =
给定一个n位(不超过10)的整数,将该数按位逆置,例如给定12345变成54321,12320变成2321. # 第一种方法,使用lstrip函数去反转后,数字前面的0 import math number=(input("input a number:")) if number.isdigit() and int(number)>=0: number_new=number[::-1] number_result=int(number_new.lstrip(")) el
4种方法,都是四舍五入,例: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public class format { double f = 111231.5585; public void m1() { BigDecimal bg = new BigDecimal(f); double f1 = bg.setScale(2, BigDecimal.ROUND