Rounding the decimal number only

mohamedmatter

Registered User.
Local time
Today, 02:21
Joined
Oct 25, 2015
Messages
122
I want to Rounding the decimal number only as show in column b by condition use round function Attach sample file by request
 

Attachments

Write your own function and use that instead of Round()
 
I am confused. What is wrong with Round() function? By what 'condition'?
 
It's not rounding per ser, it's conditional rounding by the look of it .
e.g. keep the .05 if it's exactly a .05 - I think you need a function.

I might have ten minutes tor knock one up ....
 
It's not rounding per ser, it's conditional rounding by the look of it .
e.g. keep the .05 if it's exactly a .05 - I think you need a function.

I might have ten minutes tor knock one up ....

yes my request in column B attach file
 
This will do it.
Code:
Public Function fnRoundedWithHalfs(varNumber As Currency) As Currency
 [COLOR="SeaGreen"]   ' Returns either rounded up or down value unless its .05 in which case keep it.
    ' Will guarantee there is a more elegant way of doing this but I have a glass of red in my hand.
    ' ©  Minty @ AWF ;)
 [/COLOR]   
    Dim sNumber As String
    Dim iAddItBack As Currency
    Dim iWorking As Long
     
    sNumber = Int(varNumber * 100)
    'Debug.Print sNumber
    If Right(sNumber, 1) = "5" Then
        iAddItBack = 0.05
    End If
  
   [COLOR="SeaGreen"] ' Now round the original[/COLOR]
    iWorking = (varNumber * 10)
    'Debug.Print iWorking
        
    fnRoundedWithHalfs = (iWorking / 10) + iAddItBack
  

End Function

You can apply the same steps in Excel
 
This will do it.
Code:
Public Function fnRoundedWithHalfs(varNumber As Currency) As Currency
 [COLOR="SeaGreen"]   ' Returns either rounded up or down value unless its .05 in which case keep it.
    ' Will guarantee there is a more elegant way of doing this but I have a glass of red in my hand.
    ' ©  Minty @ AWF ;)
 [/COLOR]   
    Dim sNumber As String
    Dim iAddItBack As Currency
    Dim iWorking As Long
     
    sNumber = Int(varNumber * 100)
    'Debug.Print sNumber
    If Right(sNumber, 1) = "5" Then
        iAddItBack = 0.05
    End If
  
   [COLOR="SeaGreen"] ' Now round the original[/COLOR]
    iWorking = (varNumber * 10)
    'Debug.Print iWorking
        
    fnRoundedWithHalfs = (iWorking / 10) + iAddItBack
  

End Function

You can apply the same steps in Excel

thank you for your effort . I wanted to do this using formula
 
request in my image
 

Attachments

  • sshot-1.jpg
    sshot-1.jpg
    98.6 KB · Views: 219
Non-VBA:

=IF(RIGHT(TEXT(A2,"0.00"),1)="5",A2,ROUND(A2,1))
 
Last edited:

Users who are viewing this thread

Back
Top Bottom