【问题标题】:textbox not showing decimal places\文本框不显示小数位\
【发布时间】:2017-10-06 03:01:49
【问题描述】:

来自用户表单
numberupdown 1 是 F,
numberupdown 2 是 L,
numberupdown 3 是 W,
文本框是CF,
计算是button1。

计算公式为

F-(F*(L^2)/(W^2)

基本上这需要灌溉枢轴的流量,并冲出转弯所需的流量。

输入数字是公制,结果是英制美国 GPM。

我已经把它翻译成:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles    Button1.Click
    Dim AA, BB, CC, DD As Integer    'sets up the variables
    AA = F.Value * 15.8503    'takes the value in f and converts it to US GPM
    BB = L.Value * 3.2808    'takes the value in f and converts it to feet
    CC = W.Value * 3.2808    'takes the value in f and converts it to feet
    DD = AA - (AA * (Math.Pow(BB, 2) / (Math.Pow(CC, 2))))    'the math bit
    CF.Text = String.Format("{0:n2}", DD)    'puts result in this textbox
End Sub

我追求的最终数字是 323.84,但它坚持将结果四舍五入到 324 我把 string.format("{0:n2}",DD) 显示为 2 位小数,但它们显示为 0.00,而不是 0.84。

谁能帮我解决这个问题?

【问题讨论】:

  • 如果您使用Option Strict On,它会指出尝试将浮点值分配给整数变量等问题。但是,它不会指出角流单位的标签应该是“US GPM”,而不是“l/s”。

标签: vb.net decimal


【解决方案1】:

您已将 AABBCCDD 声明为整数。整数只能存储整数。根据这些数据所代表的内容,您可以使用DecimalDouble

【讨论】:

  • 就是这个,我用过Double,对我有用,非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-28
  • 1970-01-01
  • 2012-10-04
  • 1970-01-01
  • 2021-09-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多