0

i make mini calculation and need to round the result to the biggest quarter example :

if result 1.12 be 1.25 1.32 be 1.50 1.52 be 1.75 1.80 be 2.00

Billy Moukas
  • 47
  • 1
  • 12

3 Answers3

1

You can find a good answer here (posted by sehe):

VBA: Round up to the nearest multiple of a number

For your need just change the type of the second paramter into double:

Public Function RoundUp(dblNumToRound As Double, lMultiple As Double) As Double
sporc
  • 387
  • 1
  • 4
  • 14
0

Check this example.You can use something like this:

Round a decimal to the nearest quarter in C#

Billy Moukas
  • 47
  • 1
  • 12
  • I hope this link will solve your problem. [link](http://www.vbforums.com/showthread.php?64997-Rounding-to-nearest-25) – Billy Moukas Jan 22 '18 at 11:50
0

to round to the biggest quarter you first add 0.24 and then round down to a quarter

to round down to a quarter you first multiply by 4, round the number down, and then divide by 4

'1 form with
'  1 textbox       : Name=Text1
'  1 commandbutton : Name=Command1
Option Explicit

Private Sub Command1_Click()
  Dim sngVal As Single
  sngVal = Val(Text1.Text)
  sngVal = sngVal + 0.24
  sngVal = sngVal * 4
  sngVal = Fix(sngVal)
  sngVal = sngVal / 4
  Caption = CStr(sngVal)
End Sub
Hrqls
  • 2,944
  • 4
  • 34
  • 54