424,963 Members | 941 Online
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

# Rounding a number up

 P: n/a I want to round a currency value up to the nearest 50c. ATM I'm doing this....... Dim ChrgRU as Double Dim ItmCst as Currency Dim ItmQty as Long ChrgRU = ItmCst * ItmQty If ((ChrgRU * 100) Mod 100) > 0 And ((ChrgRU * 100) Mod 100) < 50 Then ChrgRU = ((ChrgRU * 100) \ 100) + 0.5 ElseIf ((ChrgRU * 100) Mod 100) > 50 Then ChrgRU = ((ChrgRU * 100) \ 100) + 1 Else ChrgRU = ChrgRU End If Me.LblCost.Caption = Format(ChrgRU, "\$##,##0.00") ......now, I know this is not very elegant. Does anyone have a better idea? Have I overlooked something (like a function) that does what I'm after? Chhers! Nov 13 '05 #1
5 Replies

 P: n/a Access 2000 and later have a Round() function, so how about: Round(ChrgRU * 2, 0) / 2 If you are working with an older version, there's a Round() function here: http://www.mvps.org/access/modules/mdl0054.htm -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "MS" wrote in message news:%I***************@news-server.bigpond.net.au...I want to round a currency value up to the nearest 50c. ATM I'm doing this....... Dim ChrgRU as Double Dim ItmCst as Currency Dim ItmQty as Long ChrgRU = ItmCst * ItmQty If ((ChrgRU * 100) Mod 100) > 0 And ((ChrgRU * 100) Mod 100) < 50 Then ChrgRU = ((ChrgRU * 100) \ 100) + 0.5 ElseIf ((ChrgRU * 100) Mod 100) > 50 Then ChrgRU = ((ChrgRU * 100) \ 100) + 1 Else ChrgRU = ChrgRU End If Me.LblCost.Caption = Format(ChrgRU, "\$##,##0.00") .....now, I know this is not very elegant. Does anyone have a better idea? Have I overlooked something (like a function) that does what I'm after? Nov 13 '05 #2

 P: n/a "MS" wrote in message news:%I***************@news-server.bigpond.net.au... I want to round a currency value up to the nearest 50c. ATM I'm doing this....... Dim ChrgRU as Double Dim ItmCst as Currency Dim ItmQty as Long ChrgRU = ItmCst * ItmQty If ((ChrgRU * 100) Mod 100) > 0 And ((ChrgRU * 100) Mod 100) < 50 Then ChrgRU = ((ChrgRU * 100) \ 100) + 0.5 ElseIf ((ChrgRU * 100) Mod 100) > 50 Then ChrgRU = ((ChrgRU * 100) \ 100) + 1 Else ChrgRU = ChrgRU End If Me.LblCost.Caption = Format(ChrgRU, "\$##,##0.00") .....now, I know this is not very elegant. Does anyone have a better idea? Have I overlooked something (like a function) that does what I'm after? Chhers! This is a little more streamlined (and works) Format(Int(ChrgRU / -0.5) * -0.5, "\$##,##0.00") Regards, Randy Nov 13 '05 #3

 P: n/a "Allen Browne" wrote in message news:42***********************@per-qv1-newsreader-01.iinet.net.au... Access 2000 and later have a Round() function, so how about: If you are working with an older version, there's a Round() function here: http://www.mvps.org/access/modules/mdl0054.htm -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. Allen, please correct me if I'm wrong, but I don't think that Round rounds "up". Nov 13 '05 #4

 P: n/a Round() rounds the 1,2,3, 4 down, and the 6,7,8,9 up. For the 5, it uses bankers rounding, i.e. it rounds towards the even number: ? Round(2.5), Round(3.5) 2 4 -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Randy Harris" wrote in message news:NQ***************@newssvr17.news.prodigy.com. .. "Allen Browne" wrote in message news:42***********************@per-qv1-newsreader-01.iinet.net.au... Access 2000 and later have a Round() function, so how about: If you are working with an older version, there's a Round() function here: http://www.mvps.org/access/modules/mdl0054.htm Allen, please correct me if I'm wrong, but I don't think that Round rounds "up". Nov 13 '05 #5

 P: n/a "Allen Browne" wrote in message news:42***********************@per-qv1-newsreader-01.iinet.net.au... Round() rounds the 1,2,3, 4 down, and the 6,7,8,9 up. For the 5, it uses bankers rounding, i.e. it rounds towards the even number: ? Round(2.5), Round(3.5) 2 4 But that's not what the OP asked for. "Round" is not the same as "round up". What he wants is: 9.10 -> 9.50 9.45 -> 9.50 9.55 -> 10.00 Nov 13 '05 #6

### This discussion thread is closed

Replies have been disabled for this discussion.