Rounding problems!

  • Thread starter Niklas Östergren
  • Start date
N

Niklas Östergren

Is there a built in function in A2003 that allways round up to next integer?

I want to round as follows:

0,87 = 1
1,2 = 2
1,9 = 2

Or do I have to create a function for it?

TIA!
// Niklas
 
T

Tom Wickerath

Hi Niklas,

You'll have to create your own function. I would have volunteered one, but since I recognize
your as a fairly talented Access developer, I leave this for you to do.

Oh, and by the way, what's your favorite motorcycle for those summer-time rides? Road bike or
dirt? I used to race motocross many years ago....125 & 250 cc class.

Tom
________________________________


Is there a built in function in A2003 that allways round up to next integer?

I want to round as follows:

0,87 = 1
1,2 = 2
1,9 = 2

Or do I have to create a function for it?

TIA!
// Niklas
 
A

Allen Browne

You want to round everything up to the next number?

Int() rounds down, so negate it to round up. Try:
-Int(-[MyNumber])
 
N

Niklas Östergren

Hi Tom!

Thak´s a lot! I´ll make a function my self, no problem. I just wanted to
know if there was some allready built in!

Well I´m the kind of guy thar rides on the road nowdays. Between 1989 and
1994 I competed in roadracing (tarmack track´s). But it was to expensive so
I hade to quit :-(. I guess this makes me to a quit fast guy at the public
roads. But I try to think of where to open up the throttles and where NOT
to.

Have never tried Moto Cross but I´d love to try Enduro.

By the way, it´s winter time here now but since I live in the south part of
Sweden we don´t have any snow yet. We hade a couple of weeks ago and it will
be back. So at the moment my bike (Honda VFR) is in the garage been taken
care of (service). A great bike and what quality!!!

What do you ride?

Thanks anyway for giving me a quick answere!
// Niklas
 
N

Niklas Östergren

Thank´s Allen!

I didn´t know about Int() function before so I used this in a function to
give med the next higher integer of a double variable. Like this:

NextHigherInteger = Int(dblValue) + 1

I´m going to use this in my application several times so I can as well
create a simple function like this.

Thank´s for sharing your knowledge!

// Niklas

Allen Browne said:
You want to round everything up to the next number?

Int() rounds down, so negate it to round up. Try:
-Int(-[MyNumber])

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Niklas Vstergren said:
Is there a built in function in A2003 that allways round up to next
integer?

I want to round as follows:

0,87 = 1
1,2 = 2
1,9 = 2

Or do I have to create a function for it?

TIA!
// Niklas
 
A

Allen Browne

Of course that will give the wrong result if the dblValue happens to be an
exact whole number.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Niklas Vstergren said:
Thank4s Allen!

I didn4t know about Int() function before so I used this in a function to
give med the next higher integer of a double variable. Like this:

NextHigherInteger = Int(dblValue) + 1

I4m going to use this in my application several times so I can as well
create a simple function like this.

Thank4s for sharing your knowledge!

// Niklas

Allen Browne said:
You want to round everything up to the next number?

Int() rounds down, so negate it to round up. Try:
-Int(-[MyNumber])


Niklas Vstergren said:
Is there a built in function in A2003 that allways round up to next
integer?

I want to round as follows:

0,87 = 1
1,2 = 2
1,9 = 2

Or do I have to create a function for it?

TIA!
// Niklas
 
N

Niklas Östergren

Yes, you are right.

I didn´t think of that!

I´ll take a closer look at it.

// Niklas

Allen Browne said:
Of course that will give the wrong result if the dblValue happens to be an
exact whole number.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Niklas Vstergren said:
Thank4s Allen!

I didn4t know about Int() function before so I used this in a function to
give med the next higher integer of a double variable. Like this:

NextHigherInteger = Int(dblValue) + 1

I4m going to use this in my application several times so I can as well
create a simple function like this.

Thank4s for sharing your knowledge!

// Niklas

Allen Browne said:
You want to round everything up to the next number?

Int() rounds down, so negate it to round up. Try:
-Int(-[MyNumber])


Is there a built in function in A2003 that allways round up to next
integer?

I want to round as follows:

0,87 = 1
1,2 = 2
1,9 = 2

Or do I have to create a function for it?

TIA!
// Niklas
 
N

Niklas Östergren

Well this is better!

'===========================
If dblValue / Int(dblValue) = 1 Then
NextHigherInteger = Int(dblValue)
Else
NextHigherInteger = Int(dblValue) + 1
End If
'===========================

Thank´s for correcting me and making me notising the fault!

// Niklas

Allen Browne said:
Of course that will give the wrong result if the dblValue happens to be an
exact whole number.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Niklas Vstergren said:
Thank4s Allen!

I didn4t know about Int() function before so I used this in a function to
give med the next higher integer of a double variable. Like this:

NextHigherInteger = Int(dblValue) + 1

I4m going to use this in my application several times so I can as well
create a simple function like this.

Thank4s for sharing your knowledge!

// Niklas

Allen Browne said:
You want to round everything up to the next number?

Int() rounds down, so negate it to round up. Try:
-Int(-[MyNumber])


Is there a built in function in A2003 that allways round up to next
integer?

I want to round as follows:

0,87 = 1
1,2 = 2
1,9 = 2

Or do I have to create a function for it?

TIA!
// Niklas
 
T

Tom Wickerath

What do you ride?
We have to go back to the '70's and early '80's for my motorcycle riding days. In 1974, I had a
part-time job at the local Yamaha / Husqvarna shop as an apprentice mechanic while still in High
School. I was allowed to take demo bikes out to the weekend races, as long as a potential
customer had not already checked out a given bike. This usually always meant that I never got to
race the new (at the time) Yamaha bikes that had the monoshock suspension system. Those demo
bikes were usually in very hot demand. I usually ended up racing a Husky 125. Fairly nice
suspension, but it didn't have a reed valve, so it could be easy at times to flood out if you
allowed the engine to slow down too much (like when navigating through the middle of a 12" deep
puddle that was 10 feet long!). Hey, isn't Husqvarna a product of Sweden?

I also was able to purchase a brand new Yamaha TX-500A in 1974 (not bad for a kid still in high
school, huh?). This was a double overhead cam twin cylinder road bike. I put nearly 30,000 miles
on this bike, touring up and down the west coast of the US (specifically Highway 101), with an
occasional jaunt into Canada and one trip down to Tijuana, Mexico.

My biking days have long since ended.....at least for the present time.

Tom
______________________________________


Hi Tom!

Thak´s a lot! I´ll make a function my self, no problem. I just wanted to
know if there was some allready built in!

Well I´m the kind of guy thar rides on the road nowdays. Between 1989 and
1994 I competed in roadracing (tarmack track´s). But it was to expensive so
I hade to quit :-(. I guess this makes me to a quit fast guy at the public
roads. But I try to think of where to open up the throttles and where NOT
to.

Have never tried Moto Cross but I´d love to try Enduro.

By the way, it´s winter time here now but since I live in the south part of
Sweden we don´t have any snow yet. We hade a couple of weeks ago and it will
be back. So at the moment my bike (Honda VFR) is in the garage been taken
care of (service). A great bike and what quality!!!

What do you ride?

Thanks anyway for giving me a quick answere!
// Niklas
 
N

Niklas Östergren

Which offcourse gave me problem if the result of Int(dblValue) = 0. So I
changes the code tho this, which seams to work:

'===================================
If Int(dblValue) = 0 Then
NextHigherInteger = Int(dblValue) + 1
GoTo Exit_Procedure
End If

If dblValue / Int(dblValue) = 1 Then
NextHigherInteger = Int(dblValue)
Else
NextHigherInteger = Int(dblValue) + 1
End If
'==================================

Maby this might be done easyer, if so pleas let me know, but I have tryed
this one and it seams to work, so fare :)

// Niklas


Niklas Östergren said:
Well this is better!

'===========================
If dblValue / Int(dblValue) = 1 Then
NextHigherInteger = Int(dblValue)
Else
NextHigherInteger = Int(dblValue) + 1
End If
'===========================

Thank´s for correcting me and making me notising the fault!

// Niklas

Allen Browne said:
Of course that will give the wrong result if the dblValue happens to be
an exact whole number.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Niklas Vstergren said:
Thank4s Allen!

I didn4t know about Int() function before so I used this in a function
to give med the next higher integer of a double variable. Like this:

NextHigherInteger = Int(dblValue) + 1

I4m going to use this in my application several times so I can as well
create a simple function like this.

Thank4s for sharing your knowledge!

// Niklas

"Allen Browne" <[email protected]> skrev i meddelandet
You want to round everything up to the next number?

Int() rounds down, so negate it to round up. Try:
-Int(-[MyNumber])


Is there a built in function in A2003 that allways round up to next
integer?

I want to round as follows:

0,87 = 1
1,2 = 2
1,9 = 2

Or do I have to create a function for it?

TIA!
// Niklas
 
N

Niklas Östergren

"Hey, isn't Husqvarna a product of Sweden?"

Well, yes it was until ...??? 5 - 8 years ago when Italian Cagiva bought the
whole factory and moved all jobs down to Italy :-(

The people who worked at Husqvarna, (which is a city only 150 km from where
I live) emidiatly started a new production of a bike called "Husaberg" whith
which they won World Shampion titel of Enduro the verry first year. Verry
fine bikes but expensive!

I ride a lot with my bikes, together with a friend in the motorcycle
assosiation (to which I´m now developing the db for memberships (among a lot
of other data to be stored in)). The bike I have today (Honda VFR 750 F,
1997) have made apr. 110 000 km. And my last bike (Honda VFR 750 F, 1989 =
The best bike ever built if you talke about quality) I did 223 000 km
without any major breakdown. I never ever opened the engine, accept ajusting
the valves. :)

Well 1974 I was 9 years old. But my interest of motorcycle stated early. At
those day´s I remember we hade a neighbor owning a Honda CB 750. With four
exhaust pipes :) At 9 ear´s of age we thought that every motorbike hade as
many cylinders as there was exhaous pipes (which it allmost was at that
time). And offcourse, like every young guy (even today I hear this from the
young boys at home) that it was actually possible to read on the speedometer
how fast the bike was possible to ride :-O

I have traveled a lot in europe with my bikes and people are allways so nice
to a biker and it´s farley easy to get help, if nessesary. Have hade planes
for hiring a bike in New Zeeland, a coiuple of years ago but it was to
expensive so we nevere did. Maby some time in the future!

// Niklas
 
J

John Vinson

Which offcourse gave me problem if the result of Int(dblValue) = 0. So I
changes the code tho this, which seams to work:

'===================================
If Int(dblValue) = 0 Then
NextHigherInteger = Int(dblValue) + 1
GoTo Exit_Procedure
End If

If dblValue / Int(dblValue) = 1 Then
NextHigherInteger = Int(dblValue)
Else
NextHigherInteger = Int(dblValue) + 1
End If
'==================================

I'd avoid the division by simply doing a comparison rather than a
ratio:

If dblValue = Int(dblValue) Then
NextHigherInteger = dblValue
Else
NextHigherInteger = Int(dblValue) + 1
End If

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
N

Niklas Östergren

Much simpler, i agree!

Thank´s!

// Niklas

John Vinson said:
I'd avoid the division by simply doing a comparison rather than a
ratio:

If dblValue = Int(dblValue) Then
NextHigherInteger = dblValue
Else
NextHigherInteger = Int(dblValue) + 1
End If

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Top