|
| round to upper 10 in vb.net Fra : Tor-Arne Jensen |
Dato : 30-08-02 23:58 |
|
I want to be able to round f.ex 271 to 280, 337 to 340 osv.
I've tried math.ceiling/round/floor, but cant get it to work
(probably cause i am a beginner :) )
would be gratefull for all help...
TA
| |
Steen Gellett (31-08-2002)
| Kommentar Fra : Steen Gellett |
Dato : 31-08-02 08:37 |
|
Dit tal er A .........eks.337
Dit resultat B ..........i dette eksempel = 440
Hvis ikke du kan følge formlen, så er forklaringen her :
Du laver en division med 10 ( fordi du vil oprunde til nærmeste 10) hvor du fjerner alt efter kommaet ( INT
).......derefter ganger du igen med 10. Til sidst lægger du 10 til for at runde op til nærmeste 10..........håber du
forstod det ?
A = 337
B = (Int(A / 10) * 10) + 10
Tor-Arne Jensen skriver:
> I want to be able to round f.ex 271 to 280, 337 to 340 osv.
> I've tried math.ceiling/round/floor, but cant get it to work
> (probably cause i am a beginner :) )
> would be gratefull for all help...
>
> TA
--
Med venlig hilsen
Steen Gellett
Member of: DanishTeamRC5-64 Calculation - Team ID#:6635
Mailto:steen@gellett.net
| |
Steen Gellett (31-08-2002)
| Kommentar Fra : Steen Gellett |
Dato : 31-08-02 14:30 |
|
B is 340................sorry for type error
Steen Gellett skriver:
> Dit tal er A .........eks.337
> Dit resultat B ..........i dette eksempel = 440
>
> Hvis ikke du kan følge formlen, så er forklaringen her :
> Du laver en division med 10 ( fordi du vil oprunde til nærmeste 10) hvor du fjerner alt efter kommaet ( INT
> ).......derefter ganger du igen med 10. Til sidst lægger du 10 til for at runde op til nærmeste 10..........håber du
> forstod det ?
>
> A = 337
> B = (Int(A / 10) * 10) + 10
>
> Tor-Arne Jensen skriver:
>
> > I want to be able to round f.ex 271 to 280, 337 to 340 osv.
> > I've tried math.ceiling/round/floor, but cant get it to work
> > (probably cause i am a beginner :) )
> > would be gratefull for all help...
> >
> > TA
>
> --
> Med venlig hilsen
> Steen Gellett
> Member of: DanishTeamRC5-64 Calculation - Team ID#:6635
> Mailto:steen@gellett.net
--
Med venlig hilsen
Steen Gellett
Member of: DanishTeamRC5-64 Calculation - Team ID#:6635
Mailto:steen@gellett.net
| |
Anders Lund (31-08-2002)
| Kommentar Fra : Anders Lund |
Dato : 31-08-02 16:36 |
|
"Steen Gellett" <steen@gellett.net> skrev i en meddelelse
news:3D707200.9AAE4C0E@gellett.net...
> A = 337
> B = (Int(A / 10) * 10) + 10
Here is a bug. Lets say that A is 340 then B becomes 350, that's not what he
wonted. This however is more correct.
If Int(A / 10) = (A / 10) Then
B = A
Else
B = (Int(A / 10) * 10) + 10
End if
The lines above fixes a bug in Steen's code.
--
Mvh
Anders Lund
Anders@zaimGED.dk
Fjern geden fra min signatur!
| |
Steen Gellett (31-08-2002)
| Kommentar Fra : Steen Gellett |
Dato : 31-08-02 08:39 |
|
UPS.........I Hope you understand danish...........I just saw your name and thought
you would understand danish..........if not plz. write again ?
Tor-Arne Jensen skriver:
> I want to be able to round f.ex 271 to 280, 337 to 340 osv.
> I've tried math.ceiling/round/floor, but cant get it to work
> (probably cause i am a beginner :) )
> would be gratefull for all help...
>
> TA
--
Med venlig hilsen
Steen Gellett
Member of: DanishTeamRC5-64 Calculation - Team ID#:6635
Mailto:steen@gellett.net
| |
Tor-Arne Jensen (31-08-2002)
| Kommentar Fra : Tor-Arne Jensen |
Dato : 31-08-02 18:37 |
|
thx, that worked fine
"Steen Gellett" <steen@gellett.net> wrote in message
news:3D7072A2.C32D8772@gellett.net...
> UPS.........I Hope you understand danish...........I just saw your name
and thought
> you would understand danish..........if not plz. write again ?
>
> Tor-Arne Jensen skriver:
>
> > I want to be able to round f.ex 271 to 280, 337 to 340 osv.
> > I've tried math.ceiling/round/floor, but cant get it to work
> > (probably cause i am a beginner :) )
> > would be gratefull for all help...
> >
> > TA
>
> --
> Med venlig hilsen
> Steen Gellett
> Member of: DanishTeamRC5-64 Calculation - Team ID#:6635
> Mailto:steen@gellett.net
>
>
| |
Tomas Christiansen (31-08-2002)
| Kommentar Fra : Tomas Christiansen |
Dato : 31-08-02 23:46 |
|
Tor-Arne Jensen wrote:
> thx, that worked fine
Assuming that you are working with integers (longs) and that you
always want to round up to the nearest number dividable by 10, you
should use this formula:
RoundedNumber = ((Number + 9) \ 10) * 10
-------
Tomas
| |
|
|