如何创建计算除法的函数 [英] How can I create a function to calculate a division

查看:117
本文介绍了如何创建计算除法的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个viewmodel,我想在为Amount输入值时自动计算月度。当用户输入Amount的值时,必须将其除以12以获得Monthly.kindly帮助的获取结果。我需要一个函数来计算每月。



我尝试过:



I have a viewmodel and i want to calculate the Monthly automatically when value is entered for Amount. The moment user enters the value for Amount,it must be divided by 12 to the get results for Monthly.kindly help. I need a function to calculate the Monthly.

What I have tried:

public Notch GetModel()
    {
        Notch j = new Notch();
        j.Id = this.Id;
        j.Name = this.Name;
        j.Status = this.Status;
        j.Amount = this.Amount;
        j.SalaryGradeId = this.SalaryGradeId;
        j.Monthly = this.Monthly;

        return j;
    }

    public NotchViewModel()
    {
        Repository rep = new Repository();
        ActiveList = Helper.GetActiveList();
        SalaryGradeList = rep.GetSalaryGrades();
        Id = 0;
        Status = 1;
    }
    public NotchViewModel(Notch j)
        : this()
{

    this.Id = j.Id;
    this.Amount = j.Amount;
    this.Status = j.Status;
    this.Name = j.Name;
    this.SalaryGradeId = j.SalaryGradeId;
        this.Monthly = j.Monthly;
}

推荐答案

如果这是C#,您可以将Amount设为属性,并让setter也设置每月值。你也可能只是每月都有一个返回Amount / 12的属性,并且没有setter。如果它是javascript,那么你需要通过函数设置它来更新这两个值。如果是打字稿,支持属性,您可以使用C#解决方案
IF this is C#, you can make Amount a property, and have the setter also set the monthly value. You could also just have monthly be a property that returns Amount/12, and doesn't have a setter. If it's javascript, then you need to have it set through a function, to update both values. If it's typescript, that supports properties and you can use the C# solution


这篇关于如何创建计算除法的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆