how to display the result of double data type in the decimal places request by user?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vbwire
    New Member
    • Jan 2008
    • 19

    how to display the result of double data type in the decimal places request by user?

    i use vb 6.0

    this is my work..

    Code:
       1.
          Option Explicit
       2.
           
       3.
          Dim Error As Double
       4.
          Dim x As Double
       5.
          Dim y As Double
       6.
          Dim z As Integer
       7.
          Dim eps As Double
       8.
          Dim a As Integer
       9.
          Dim N As Integer
      10.
           
      11.
          Private Sub cmdCalculate_Click()
      12.
           
      13.
          'user input
      14.
           
      15.
          If IsNumeric(txtN) And IsNumeric(txtEps) And IsNumeric(txtX) Then
      16.
          N = txtN.Text
      17.
          a = txtEps.Text
      18.
          x = txtX.Text
      19.
          Else
      20.
              MsgBox "all input must be numeric", vbExclamation, "numeric test"
      21.
              txtN.SetFocus
      22.
          End If
      23.
           
      24.
          'calculate
      25.
           
      26.
          eps = (10 ^ (-a))
      27.
           
      28.
          Do
      29.
              y = x - (x - (N ^ (1 / 3)))
      30.
           
      31.
              Error = Abs(y - x)
      32.
             
      33.
              x = y
      34.
           
      35.
              z = z + 1
      36.
             
      37.
          Loop Until Error < eps
      38.
           
      39.
          'display the result
      40.
          lblDisplay.Caption = "root : " & y & "             iteration : " & z
      41.
           
      42.
          End Sub
      43.
           
      44.
          Private Sub cmdExit_Click()
      45.
          Unload Me
      46.
          End Sub
    how to make the answer appear in the lable be in the decimal places user wants.. for example,if they put 3 in the txtEps,then the result is something like 0.123..
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Use the Format() function to take a number and return it as a string formatted the way you want. Look up the specifics in your documentation.

    Comment

    Working...