Solved

# ROUNDED TO 500 OR 1000

Posted on 2011-03-21
291 Views
Hi All,

I want to round to 500 or 1000 depends on the value.

If the value less than 500 then rounded to 500
If the value greater then 500 then rounded to 1000.

Does my code works for those condition ?

Thank you.

``````lblGrandTotal.Text = (Math.Round(CDbl(lblSubTotal.Text) / 500, 0)) * 500

If CDbl(Me.lblSubTotal.Text) > CDbl(lblGrandTotal.Text) Then
lblGrandTotal.Text = CDbl(lblGrandTotal.Text) + 500
End If
``````
0
Question by:emi_sastra

LVL 39

Expert Comment

ID: 35179917
Do like this if you have only two conditions

if  (Convert.ToInt32(lblSubTotal.Text) <=500 )
lblGrandTotal.Text = 500
else
lblGrandTotal.Text = 1000
End if
0

LVL 1

Author Comment

ID: 35179939
Hi pratima_mcs,

I also mean 100,600 will be rounded to 101,000.
I also mean 100,300 will be rounded to 100,500.

Thank you.
0

LVL 53

Accepted Solution

Dhaest earned 500 total points
ID: 35179943
So you'll always round up to the nearest 500 ?

If so, try this:

lblGrandTotal.Text = Math.Ceiling(CDbl(lblGrandTotal.Text)/ 500) * 500
0

LVL 11

Expert Comment

ID: 35179944

if value is 525 then it rounds to 500 is it right?

same way, if value is 1025 then it rounds to 1000 but if value is 1475 then it rounds to 1500.

If you want to round the number to 500 and 1000 only (not 1500) then there is some error in the code.

0

LVL 1

Author Comment

ID: 35179987
Hi Dhaest,

It works.

Thank you very much for your help.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …