vb.net 在文本框中处理货币值

vb.net working with currency values in text boxes

我的应用程序中有一个用于添加订单的简单表单。

它包含两个文本框控件,'neworder_costprice' 和 'neworder_saleprice'。 我还有一个滑块控件,markup_percent',它可以是 0 到 100 之间的一个值,以 10 为增量。

我正在努力做到这一点,如果用户在 costprice 文本框中键入“1.20”,则销售价格文本框将自动填充 costprice + markup_percent.[=12= 的值]

我已经尝试了几种不同的方法来让它工作,但似乎没有人愿意为我做这件事!谁能指出我方法的错误?

以下是我在 costprice.valuechanged 上调用的 'workoutsaleprice()' 函数的当前代码...

tech_neworder_costprice.Text = String.Format("{0:n2}", neworder_costprice.Text)           

Dim costprice As Double = neworder_costprice.Text
Dim markup As Integer = percent_slider.Value

Dim saleprice As Double = ((costprice / 100) * markup) + costprice
neworder_saleprice.Text = saleprice.ToString

使用 NumericUpDown 而不是 TextBox 作为数字输入。验证是自动处理的,因此保证永远不会有非数字值。

您可以改为使用 Decimal 类型的 NumericUpDown.Value 属性 来执行数值运算。