Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

round a number to the next highest number,regardless of value of reciprocal

Posted on 2003-12-11
8
Medium Priority
?
365 Views
Last Modified: 2010-05-01
dim x as single

if its x.0
i want it to stay x

if its x.1 - x.9 i want to to change to (x+1)


thanks!
0
Comment
Question by:jxharding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9920508
Will this work?

Private Sub Command1_Click()
x = 1.9
MsgBox Round(x + 0.4)
End Sub
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9920519
jxharding,
    Add .5 to the value as you round it.

Dang123
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9920536


Dim x as Single
IF x - Abs ( x ) > 0 THEN
   x = Abs ( x ) + 1
END IF
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Expert Comment

by:crazyman
ID: 9920815

Function FixIt(n As Single)
    FixIt = n + IIf(n <> Int(n), (1 - (n - Int(n))), 0)
End Function
0
 
LVL 6

Expert Comment

by:srimanth
ID: 9921465
try this:

msgbox Convert(5.0)
msgbox Convert(5.1)
...
msgbox Convert(5.9)

Private Function Convert(strVal As Single)
    Convert = IIf((strVal * 10) \ 10 = strVal, strVal, Int(strVal + 1))
End Function

cheers,
srimanth.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 9921915
So that you get uniform results with negatives here is a simple but comprehensive function.

Hope this helps:~)

Function RoundToNext(psngNumeric As Single) As Single ' or whatevery type you need.

RoundToNext = Sgn(psngNumeric) * Int(Abs(psngNumeric) + 0.9999)

End Function
0
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 9923119
Dim x As Single
Dim y() As Single
Dim z As Single

Private Sub Command1_Click()
x = Text1.Text
End Sub
If InStr(1, x, ".") Then
y() = Split(x, ".")
z = x - y(0)
x = x + (0.1 - z)
End If
MsgBox x
Exit Sub


that might work, I'm not at home right now so i can't test it...
0
 
LVL 4

Accepted Solution

by:
learning_t0_pr0gram earned 1000 total points
ID: 9923598
sorry.. got home and fixed it, should be:

Dim x As Single
Dim y() As String
Dim z As Single

Private Sub Command1_Click()
x = Text1.Text
If InStr(1, x, ".") Then
y() = Split(x, ".")
z = x - y(0)
x = x + (1 - z)
End If
MsgBox x
End Sub
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

618 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