Refer to the discussion earlier, how can I get 4.73 if I want convert 4.725 to 2 decimal place?
Rounding Numbers: Round2 or Numberformat2
Here is what I tried:
Results:
Rounding Numbers: Round2 or Numberformat2
Here is what I tried:
B4X:
Dim dblValue As Double
dblValue = 4.704
For i = 0 To 9
dblValue = NumberFormat(dblValue, 0, 3)
Log("Number: " & dblValue)
Log("NumberFormat(" & dblValue & ", 1, 2) = " & NumberFormat(dblValue, 1, 2))
Log("Round2(" & dblValue & ", 2) = " & Round2(dblValue, 2))
Log("-------------------------------------------------------")
dblValue = dblValue + 0.01
Next
dblValue = 4.705
For i = 0 To 9
dblValue = NumberFormat(dblValue, 0, 3)
Log("Number: " & dblValue)
Log("NumberFormat(" & dblValue & ", 1, 2) = " & NumberFormat(dblValue, 1, 2))
Log("Round2(" & dblValue & ", 2) = " & Round2(dblValue, 2))
Log("-------------------------------------------------------")
dblValue = dblValue + 0.01
Next
dblValue = 4.706
For i = 0 To 9
dblValue = NumberFormat(dblValue, 0, 3)
Log("Number: " & dblValue)
Log("NumberFormat(" & dblValue & ", 1, 2) = " & NumberFormat(dblValue, 1, 2))
Log("Round2(" & dblValue & ", 2) = " & Round2(dblValue, 2))
Log("-------------------------------------------------------")
dblValue = dblValue + 0.01
Next
Log("Extra")
Log("-------------------------------------------------------")
dblValue = 4.80
Log("Number: " & dblValue)
dblValue = NumberFormat(dblValue, 1, 2)
Log("NumberFormat(" & dblValue & ", 1, 2) = " & NumberFormat(dblValue, 1, 2))
Log("NumberFormat2(" & dblValue & ", 1, 2, 2, False) = " & NumberFormat2(dblValue, 1, 2, 2, False))
Log("Round(" & dblValue & ") = " & Round(dblValue))
Log("Round2(" & dblValue & ", 1) = " & Round2(dblValue, 1))
Log("Round2(" & dblValue & ", 2) = " & Round2(dblValue, 2))
Log("-------------------------------------------------------")
Log("Extra 2")
Log("-------------------------------------------------------")
dblValue = 4.725
Log("Number: " & dblValue)
dblValue = NumberFormat(dblValue, 1, 3)
Log("NumberFormat(" & dblValue & ", 0, 2) = " & NumberFormat(dblValue, 0, 2))
Log("NumberFormat(" & dblValue & ", 1, 2) = " & NumberFormat(dblValue, 1, 2))
Log("NumberFormat2(" & dblValue & ", 0, 2, 2, False) = " & NumberFormat2(dblValue, 0, 2, 2, False))
Log("NumberFormat2(" & dblValue & ", 1, 2, 2, False) = " & NumberFormat2(dblValue, 1, 2, 2, False))
Log("Round(" & dblValue & ") = " & Round(dblValue))
Log("Round2(" & dblValue & ", 1) = " & Round2(dblValue, 1))
Log("Round2(" & dblValue & ", 2) = " & Round2(dblValue, 2))
Log("Ceil(" & dblValue & ") = " & Ceil(dblValue))
Log("Floor(" & dblValue & ") = " & Floor(dblValue))
Results:
B4X:
Number: 4.704
NumberFormat(4.704, 1, 2) = 4.7
Round2(4.704, 2) = 4.7
-------------------------------------------------------
Number: 4.714
NumberFormat(4.714, 1, 2) = 4.71
Round2(4.714, 2) = 4.71
-------------------------------------------------------
Number: 4.724
NumberFormat(4.724, 1, 2) = 4.72
Round2(4.724, 2) = 4.72
-------------------------------------------------------
Number: 4.734
NumberFormat(4.734, 1, 2) = 4.73
Round2(4.734, 2) = 4.73
-------------------------------------------------------
Number: 4.744
NumberFormat(4.744, 1, 2) = 4.74
Round2(4.744, 2) = 4.74
-------------------------------------------------------
Number: 4.754
NumberFormat(4.754, 1, 2) = 4.75
Round2(4.754, 2) = 4.75
-------------------------------------------------------
Number: 4.764
NumberFormat(4.764, 1, 2) = 4.76
Round2(4.764, 2) = 4.76
-------------------------------------------------------
Number: 4.774
NumberFormat(4.774, 1, 2) = 4.77
Round2(4.774, 2) = 4.77
-------------------------------------------------------
Number: 4.784
NumberFormat(4.784, 1, 2) = 4.78
Round2(4.784, 2) = 4.78
-------------------------------------------------------
Number: 4.794
NumberFormat(4.794, 1, 2) = 4.79
Round2(4.794, 2) = 4.79
-------------------------------------------------------
Number: 4.705
NumberFormat(4.705, 1, 2) = 4.71
Round2(4.705, 2) = 4.71
-------------------------------------------------------
Number: 4.715
NumberFormat(4.715, 1, 2) = 4.71
Round2(4.715, 2) = 4.72
-------------------------------------------------------
Number: 4.725
NumberFormat(4.725, 1, 2) = 4.72
Round2(4.725, 2) = 4.72
-------------------------------------------------------
Number: 4.735
NumberFormat(4.735, 1, 2) = 4.74
Round2(4.735, 2) = 4.74
-------------------------------------------------------
Number: 4.745
NumberFormat(4.745, 1, 2) = 4.75
Round2(4.745, 2) = 4.75
-------------------------------------------------------
Number: 4.755
NumberFormat(4.755, 1, 2) = 4.75
Round2(4.755, 2) = 4.76
-------------------------------------------------------
Number: 4.765
NumberFormat(4.765, 1, 2) = 4.76
Round2(4.765, 2) = 4.76
-------------------------------------------------------
Number: 4.775
NumberFormat(4.775, 1, 2) = 4.78
Round2(4.775, 2) = 4.78
-------------------------------------------------------
Number: 4.785
NumberFormat(4.785, 1, 2) = 4.79
Round2(4.785, 2) = 4.79
-------------------------------------------------------
Number: 4.795
NumberFormat(4.795, 1, 2) = 4.79
Round2(4.795, 2) = 4.8
-------------------------------------------------------
Number: 4.706
NumberFormat(4.706, 1, 2) = 4.71
Round2(4.706, 2) = 4.71
-------------------------------------------------------
Number: 4.716
NumberFormat(4.716, 1, 2) = 4.72
Round2(4.716, 2) = 4.72
-------------------------------------------------------
Number: 4.726
NumberFormat(4.726, 1, 2) = 4.73
Round2(4.726, 2) = 4.73
-------------------------------------------------------
Number: 4.736
NumberFormat(4.736, 1, 2) = 4.74
Round2(4.736, 2) = 4.74
-------------------------------------------------------
Number: 4.746
NumberFormat(4.746, 1, 2) = 4.75
Round2(4.746, 2) = 4.75
-------------------------------------------------------
Number: 4.756
NumberFormat(4.756, 1, 2) = 4.76
Round2(4.756, 2) = 4.76
-------------------------------------------------------
Number: 4.766
NumberFormat(4.766, 1, 2) = 4.77
Round2(4.766, 2) = 4.77
-------------------------------------------------------
Number: 4.776
NumberFormat(4.776, 1, 2) = 4.78
Round2(4.776, 2) = 4.78
-------------------------------------------------------
Number: 4.786
NumberFormat(4.786, 1, 2) = 4.79
Round2(4.786, 2) = 4.79
-------------------------------------------------------
Number: 4.796
NumberFormat(4.796, 1, 2) = 4.8
Round2(4.796, 2) = 4.8
-------------------------------------------------------
Extra
-------------------------------------------------------
Number: 4.8
NumberFormat(4.8, 1, 2) = 4.8
NumberFormat2(4.8, 1, 2, 2, False) = 4.80
Round(4.8) = 5
Round2(4.8, 1) = 4.8
Round2(4.8, 2) = 4.8
-------------------------------------------------------
Number: 4.725
NumberFormat(4.725, 0, 2) = 4.72
NumberFormat(4.725, 1, 2) = 4.72
NumberFormat2(4.725, 0, 2, 2, False) = 4.72
NumberFormat2(4.725, 1, 2, 2, False) = 4.72
Round(4.725) = 5
Round2(4.725, 1) = 4.7
Round2(4.725, 2) = 4.72
Ceil(4.725) = 5
Floor(4.725) = 4