可能重复:
如何将小数点后的数字保留两位有效数字并四舍五入
我正在尝试将十进制度数(23.1248)转换为分钟式度数(23 7'29.3")。
double a=23.1248;
int deg=(int)a;//gives me the degree
float b=(float) (a-deg);
int min=(int) (b*60);//gives me the minutes
double sec= (double) ((c*60)-min);//gives me my seconds
一切都运行良好,但我想将秒数四舍五入到最接近的十分之一或百分之一。我已经查看了小数格式化,但宁愿不将其转换为字符串。我也看过bigdecimal,但不认为会有帮助。