小编Oct*_*cto的帖子

如何获得两个数字相除的十进制余数?

因此,我正在尝试编写一个脚本,其中用户输入了他们需要行驶的英里数和每小时行驶的英里数,并且脚本输出了他们必须行驶的剩余小时数和分钟数。我一直在尝试使用%来查找行驶的英里数/ MPH的其余部分,但它输出的数字错误。无论如何,是否只能从两个除数中得到小数?例如,如果我执行100/65,则得到大约1.538的输出,我只想使用0.538。但是当我使用100%65时,我得到35。这是我当前的脚本供参考:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TimeCalculator
{
     class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Travel Time Calculator");
            string answer;
            //creates variable for the answer
            do
            //creates loop to continue the application
            {
                string grade;
               //Console.WriteLine(100-(int)((double)100/65)*65);
                Console.WriteLine(" ");
                Console.Write("Enter miles: ");
                Decimal val1 = Convert.ToDecimal(Console.ReadLine());
               //converts input to decimal allowing user to use decimals
                Console.Write("Enter miles per hour: ");
                Decimal val2 = Convert.ToDecimal(Console.ReadLine());
                //converts input to decimal allowing user …
Run Code Online (Sandbox Code Playgroud)

c# math decimal division

2
推荐指数
1
解决办法
2583
查看次数

标签 统计

c# ×1

decimal ×1

division ×1

math ×1