简体   繁体   English

在文本框 VB.Net 中格式化和计算数字

[英]Formatting and Computing Numbers in Textbox VB.Net

Hello Everyone Good Afternoon.大家好,下午好。 I Hope Someone Helps me with my Problem.我希望有人帮助我解决我的问题。

I have 3 Textboxes and they are:我有 3 个文本框,它们是:

GrandTotal.Text
VatAmount.Text
TotalAmount.Text

and 1 NumericUpdown1.Value和 1 个NumericUpdown1.Value

Here is the Scenario, As the system goes, there is a code that will trigger and Will put a Number value in GrandTotal.Text and after that, The User will press NumericUpdown1.Value .这是场景,随着系统的运行,有一个代码将触发并在GrandTotal.Text放置一个 Number 值,之后,用户将按下NumericUpdown1.Value Every time the user press it A computation will be triggered and a Number value will be Displayed in TotalAmount.Text and VatAmount.Text每次用户按下它都会触发一次计算,并且会在TotalAmount.TextVatAmount.Text显示一个 Number 值

To Make it more specific it is like a computation form that will include VAT.为了使它更具体,它就像一个包含增值税的计算表格。 For Example.例如。

Grandtotal.text = 2000

and if I press the NumericUpDown to + 1如果我按 NumericUpDown 到 + 1

VatAmount.Text = 20 and TotalAmount.Text = 2020 VatAmount.Text = 20 和TotalAmount.Text = 2020

I hope you get what I mean我希望你明白我的意思

and Here is my code for It:这是我的代码:

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
VatAmount.Text = Val(Grandtotal.text) * NumericUpDown1.Value * 0.01
End Sub



Private Sub VatAmount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VatAmount.TextChanged
        TotalAmount.Text = Val(VatAmount.Text) + Val(TextBox14.Text)
    End Sub

Now I`m done Explaining it here is My Question.现在我已经完成在这里解释它是我的问题。

How to put Commas on that Textboxes and Compute It?如何将逗号放在该文本框上并计算它? My Prof. asked that He wants to put commas on the numbers that will bi inputted?我的教授问他要在要输入的数字上加逗号吗? No need to literally put Commas.无需从字面上放置逗号。 Put it Automatically when value is greater that 3 Digits当值大于 3 位时自动放置

How can I put commas in Textboxes and Compute it using the NumericUpdown?如何在文本框中放置逗号并使用 NumericUpdown 计算它?

TYSM TYSM

This is roughly what you need:这大致是你需要的:

Private Sub GrandTotal_TextChanged(sender As Object, e As EventArgs) Handles GrandTotal.TextChanged
    Dim input As Double = Double.Parse(GrandTotal.Text)
    Dim inputStringWithCommas As String = input.ToString("N0", CultureInfo.InvariantCulture)
    GrandTotal.Text = inputStringWithCommas

    Dim vat As Double = Double.Parse(GrandTotal.Text) * NumericUpDown1.Value * 0.01
    VatAmount.Text = vat.ToString()
    TotalAmount.Text = (Double.Parse(GrandTotal.Text) + vat).ToString("N0", CultureInfo.InvariantCulture)
End Sub

It is similar to what you have, so you should be able to make it work for the NumericUpDown event as well.它与您拥有的类似,因此您应该能够使其也适用于 NumericUpDown 事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM