在文本框VB.NET中格式化和计算数字 [英] Formatting and computing numbers in textbox VB.NET

查看:137
本文介绍了在文本框VB.NET中格式化和计算数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,下午好。

我希望有人帮我解决问题。





我有3个文本框,它们是:



GrandTotal.Text

VatAmount.Text

TotalAmount.Text



和1`NumericUpdown1.Value`



这是方案,随着系统的进展,有一个将触发的代码并将Number值放在`GrandTotal.Text`中,之后,用户将按下`NumericUpdown1.Value`。每次用户按下它时将触发计算并在TotalAmount.Text和VatAmount.Text中显示Number值。





为了使其更具体,它就像一个包含增值税的计算表格。例如。



`Grandtotal.text = 2000`



如果我按下NumericUpDown来+ 1



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





我希望你明白我的意思



这是我的代码:







 私人  Sub  NumericUpDown1_ValueChanged( ByVal  sender  As  System。对象 ByVal  e 作为 System.EventArgs)句柄 NumericUpDown1.ValueChanged 
VatAmount.Text = Val(Grandtotal.text)* NumericUpDown1.Value * 0 01
结束 Sub









 私有  Sub  VatAmount_TextChanged( ByVal  sender  As  System。 Object  ByVal  e  As  System.EventArgs)句柄 VatAmount.TextChanged 
TotalAmount.Text = Val(VatAmount。文本)+ Val(TextBox14.Text)
结束 Sub





现在我已经完成了解释这里是我的问题。





如何将Commas放在Textbox上并计算它?我的教授问他想要用逗号输入数字吗?无需字面上放置逗号。当值大于3位时自动设置





如何在文本框中放入逗号并使用NumericUpdown计算它? />


我尝试了什么:



我试图搜索并编码但是它不能给我需要的东西

解决方案

我会读到这个标准数字格式字符串 [ ^ ]



它允许您将数字格式化为货币,同时将它们表示为用户界面的字符串。

Hello Everyone Good Afternoon.
I Hope Someone Helps me with my Problem.


I have 3 Textboxes and they are:

GrandTotal.Text
VatAmount.Text
TotalAmount.Text

and 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`. Every time the user press it A computation will be triggered and a Number value will be Displayed in `TotalAmount.Text` and `VatAmount.Text`


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

`VatAmount.Text` = 20 and `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


How can I put commas in Textboxes and Compute it using the NumericUpdown?

What I have tried:

I tried to Search and Code it but It cant Give what I needed

解决方案

I would have a read of this Standard Numeric Format Strings[^]

It will allow you to format numbers as currency while representing them as a string to the user interface.


这篇关于在文本框VB.NET中格式化和计算数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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