Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

   

Reply
 
LinkBack Thread Tools Display Modes
Old 02-26-2007, 05:22 PM   #1 (permalink)
Contributing Member
 
Nicole's Avatar
 
Join Date: 02-23-07
Location: USA
Posts: 874
iTrader: 0 / 0%
Nicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of light
VB.NET - Rounding up

I have a variable that I want to always be rounded up to the next .25

I am using VB.NET.

Examples:

1.1 would become 1.25
1.26 would become 1.5
1.75 would stay the same

Anyone know how to do this?
__________________
~Nicole

V7N Contextual Links
Nicole is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2007, 05:32 PM   #2 (permalink)
Individualist
 
John Scott's Avatar
 
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,521
iTrader: 3 / 100%
Latest Blog:
Google????

John Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster materialJohn Scott is supreme webmaster material
Send a message via AIM to John Scott Send a message via Yahoo to John Scott
http://www.freevbcode.com/ShowCode.asp?ID=1558 ?
John Scott is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2007, 06:00 PM   #3 (permalink)
Contributing Member
 
Nicole's Avatar
 
Join Date: 02-23-07
Location: USA
Posts: 874
iTrader: 0 / 0%
Nicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of light
Thanks, John



I can't get that code to work for me. Possibly because I'm using .NET. Not sure, though.

If anyone could help me understand how to get that to work, it would be great.
__________________
~Nicole

V7N Contextual Links
Nicole is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2007, 09:15 PM   #4 (permalink)
Contributing Member
 
Nicole's Avatar
 
Join Date: 02-23-07
Location: USA
Posts: 874
iTrader: 0 / 0%
Nicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of lightNicole is a glorious beacon of light
Figured out how to do this. For future reference, here it is:

This is using time and it rounds up to the next 15 minutes.

DoMath() can be replaced with any number or variable and it represents the original number of minutes (before rounding).

15 is the number to round to.

Code:
Private Function DoBillable() Dim nummins As Integer Dim n As Double Dim min As Integer Dim tot As TimeSpan nummins = 15 n = (DoMath() / nummins) min = Math.Truncate(n + 0.9) * nummins tot = New TimeSpan(0, min, 0) Return tot.TotalHours.ToString("F") End Function
There may be a more efficient way of doing this..
__________________
~Nicole

V7N Contextual Links
Nicole is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-01-2008, 02:54 PM   #5 (permalink)
Junior Member
 
Join Date: 08-01-08
Posts: 1
iTrader: 0 / 0%
Latest Blog:
None

Rien17 is liked by many
Round Up and down

RoundUp and RoundDown are two popular functions and i for one used to use them a lot..so when i started on VB i was pissed when they weren't around anymore...but! they are pretty easy to write yourself...basic versions at least...if you want a thing that handles time like this thread then it'll be a little awkward but for basic RoundUp and RoundDown then these two fucntions work perfectly, feel free to use and change this however you want I only ask that you at least leave my name on the "Created" line.
Code:
' Comment Section ' Purpose: Rounds a number up ' Parameters: num: Double - Number to be rounded up ' Returns: Integer - the number rounded up ' Change Log: ' 08-01-08: M. O'Brien - Created Public Function RoundUp(ByVal num As Double) As Integer Try 'Temp variable to hold the decimal portion of the parameter Dim temp As Double 'Get the decimal portion temp = num - Math.Truncate(num) 'If there is a decimal portion then we add 1 to force it to round up num = IIf(temp > 0, num + 1, num) 'return the truncated version of the double which should be the number rounded up Return Math.Truncate(num) Catch ex As Exception MessageBox.Show("Error occured in: " & ex.StackTrace & vbCrLf & vbCrLf & "Error: " & ex.Message, _ "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Nothing End Try End Function ' Comment Section ' Purpose: Rounds a number down ' Parameters: num: Double - Number to be rounded down ' Returns: Integer - the number rounded down ' Change Log: ' 08-01-08: M. O'Brien - Created Public Function RoundDown(ByVal num As Double) As Integer Try 'return the truncated version of the double which should be the number rounded down Return Math.Truncate(num) Catch ex As Exception MessageBox.Show("Error occured in: " & ex.StackTrace & vbCrLf & vbCrLf & "Error: " & ex.Message, _ "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Nothing End Try End Function

Last edited by Rien17 : 08-01-2008 at 03:00 PM.
Rien17 is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding corners of borders devilzfan300 Coding Forum 9 03-11-2008 02:50 AM


Sponsor Links
Webmaster Forum Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 02:53 AM.
© Copyright 2008 V7 Inc