Webmaster Forum



Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-26-2007, 04:22 PM
Nicole's Avatar
Senior Member
 
Join Date: 02-23-07
Location: USA
Posts: 860
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
Share |
Reply With Quote
  #2 (permalink)  
Old 02-26-2007, 04:32 PM
John Scott's Avatar
Individualist
Latest Blog:
Individualism.com?

 
Join Date: 09-27-03
Location: Japan, mostly
Posts: 27,703
iTrader: 3 / 100%
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 ?
__________________
Individualism .::. My Facebook - Add Me
“It is no measure of health to be well adjusted to a profoundly sick society.”
Share |
Reply With Quote
  #3 (permalink)  
Old 02-26-2007, 05:00 PM
Nicole's Avatar
Senior Member
 
Join Date: 02-23-07
Location: USA
Posts: 860
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
Share |
Reply With Quote
  #4 (permalink)  
Old 02-26-2007, 08:15 PM
Nicole's Avatar
Senior Member
 
Join Date: 02-23-07
Location: USA
Posts: 860
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
Share |
Reply With Quote
  #5 (permalink)  
Old 08-01-2008, 01:54 PM
Junior Member
 
Join Date: 08-01-08
Posts: 1
iTrader: 0 / 0%
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 02:00 PM.
Share |
Reply With Quote
Go Back   Webmaster Forum > Web Development > 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

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


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


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 02:16 AM.
Powered by vBulletin
Copyright © 2000-2011 Jelsoft Enterprises Limited.
Copyright © 2003 - 2011 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.