C# Calculator Class

前端 未结 4 917
太阳男子
太阳男子 2021-01-17 00:36

I was given this homework assignment, which I have been having a hard time with. The form was written and we had to write the class. Currently when I run the program my equa

4条回答
  •  悲哀的现实
    2021-01-17 01:10

    Let's look at the requirement:

    "The results of multipication should show no more decimal places than the result of the first number than in the second number. Example 55.5*89.68 = 4977.240"

    The natural of multiplication in basic arithmetic means that this happens by default anyway. Eg. you're never going to multiply X.X by X.XX and get result X.XXXXXXX... - it just can't happen.

    Formatting is therefore easy - if you need to explicitly format then format as num.ToString("#.##############") which allows for a while bunch of numbers.

    You haven't outlined any requirements for Division, so I can't comment.

    BTW - if you say x = 1 / 3 and y = z * x, then you are going to get a lot of numbers after the decimal place, because x is .333333333... to start with. This is within the requirement AFAICT.

提交回复
热议问题