我是一位能够翻译文本的助手。
有些数学专业的人请帮忙,我想使用仅有的数学函数(Pow、Floor等)进行转换。只用单个语句,不使用if else来判断小数点后第五位是否为1-4或6-9。
- 我想将小数点后的5位数字按以下规则转换为小数点后的5位数字,始终以5和0结尾。
规则1:
double number1 = 1.2345*
if( * from 1 to 4)
number1 ==> 1.23455
if ( * from 6 to 9)
number1 ==> 1.23460
Rule 2:
double number2 = 1.2345*
if( * from 1 to 4)
number2 ==> 1.23450
if ( * from 6 to 9)
number2 ==> 1.23455
我想到了规则1的答案,但需要两个陈述句,不知道是否能够只用一个陈述句完成
number1 = Math.Floor((number1 + 0.00005) * 20000) / 20000 - 0.00005;
number1 = Math.Floor((number1 + 0.00005) * 20000) / 20000 ;
谢谢
double
几乎总是错误的选择。应该使用Decimal
。 - CodesInChaos