Solved

ROUNDED TO 500 OR 1000

Posted on 2011-03-21
5
277 Views
Last Modified: 2012-06-27
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.

Please see below code.

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

Open in new window

0
Comment
Question by:emi_sastra
5 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
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

by:emi_sastra
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

by:
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

by:Deepak Lakkad
ID: 35179944
In your code,

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.

pls. specify your requirement properly

- Deepak Lakkad
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35179987
Hi Dhaest,

It works.

Thank you very much for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now