gpt4 book ai didi

c# - c#中提取小数点后的数字

转载 作者:太空宇宙 更新时间:2023-11-03 18:22:38 25 4
gpt4 key购买 nike

<分区>

我应该写一个程序,输入是double(变量叫做money),我应该分别打印小数点前的数字和小数点后的数字。例如:

对于输入:36.5 应该打印:小数点前的数字是:36 小数点后的数字是:5

对于输入:25.4 应该打印:小数点前的数字是:24 小数点后的数字是:4

Console.WriteLine("Enter money:");
double money = double.Parse(Console.ReadLine());
int numBeforePoint = (int)money;
double numAfterPoint = (money - (int)money)*10;
Console.WriteLine("The number beforethe decimal point is: {0}. the number after the decimal point is: {1}",numBeforePoint,numAfterPoint);

如果我输入 25.4 它会打印:小数点前的数字是:24 小数点后的数字是:3.9999999

我不想要 3.999999 我想要 4

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com