Asymmetric Rounding "Rounding-Half-Down"

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
358
Office Version
  1. 2003 or older
Platform
  1. Windows
While I have been able to code a function for Asymmetric Rounding "Rounding-Half-Up" (code attached). But, I am struggling with Asymmetric Rounding "Rounding-Half-Down" method.

Code:
Public Function RoundHalfUpAsym( _
       ByVal myNum As Double, _
       ByVal myFac As Double) As Double
        
        RoundHalfUpAsym = Int(myNum * CDec(10# ^ myFac) + 0.5) / CDec(10# ^ myFac)


End Function

The concept of Asymmetric Rounding "Rounding-Half-Down" can be referenced at:
HTML:
https://www.eetimes.com/document.asp?doc_id=1274515#A4
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,
Try this code:
Rich (BB code):
Function RoundHalfDownAsym(myNum As Double, myFac As Integer) As Double
  If myNum < 0 Then
    RoundHalfDownAsym = WorksheetFunction.RoundUp(myNum, myFac)
  Else
    RoundHalfDownAsym = WorksheetFunction.RoundDown(myNum, myFac)
  End If
End Function
Regards
 
Last edited:
Upvote 0
@ZVI;

No, it doesn't work.

[TABLE="width: 1152"]
<colgroup><col span="18"></colgroup><tbody>[TR]
[TD][/TD]
[TD]-2.0000[/TD]
[TD]-1.7000[/TD]
[TD]-1.5000[/TD]
[TD]-1.3000[/TD]
[TD]-1.0000[/TD]
[TD]-0.7000[/TD]
[TD]-0.5000[/TD]
[TD]-0.3000[/TD]
[TD]0.0000[/TD]
[TD]0.3000[/TD]
[TD]0.5000[/TD]
[TD]0.7000[/TD]
[TD]1.0000[/TD]
[TD]1.3000[/TD]
[TD]1.5000[/TD]
[TD]1.7000[/TD]
[TD]2.0000[/TD]
[/TR]
[TR]
[TD]Expected[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD]-0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Actual[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD].[/TD]
[TD].[/TD]
[TD].[/TD]
[TD]Error[/TD]
[TD].[/TD]
[TD].[/TD]
[TD].[/TD]
[TD]Error[/TD]
[TD].[/TD]
[TD].[/TD]
[TD].[/TD]
[TD]Error[/TD]
[TD].[/TD]
[TD].[/TD]
[TD].[/TD]
[TD]Error[/TD]
[TD].[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
No, it doesn't work.
My bad, use the bellow code:
Rich (BB code):
Function RoundHalfDownAsym(V As Double, Optional DecPlaces As Integer = 0) As Double
' ZVI:2019-08-26 https://www.mrexcel.com/forum/excel-questions/1108001-asymmetric-rounding-rounding-half-down.htm
  If DecPlaces < 0 Then
    RoundHalfDownAsym = Round(V / 10 ^ -DecPlaces - Sgn(V) * V * 2E-16, 0) * 10 ^ -DecPlaces
  Else
    RoundHalfDownAsym = Round(V - Sgn(V) * V * 2E-16, DecPlaces)
  End If
  If Abs(RoundHalfDownAsym) = 0 Then RoundHalfDownAsym = 0
End Function
Book1
ABCD
1ValueExpectedActual
2-2-2-2copy C2 down
3-1.5-2-2
4-1.3-1-1
5-1-1-1
6-0.7-1-1
7-0.5-1-1
8-0.300
9000
100.300
110.500
120.711
13111
141.311
151.511
161.722
17222
Sheet1
Cell Formulas
RangeFormula
C2=RoundHalfDownAsym(A2)

Regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top