Page 1 of 2
Round() Int() ...
Posted: Sun Mar 20, 2005 4:01 pm
by Psychophanta
Currently, there are no a native function to perform a rounded number from another.
Now:
1) Round(x,0) is absolutely samething as Int(x)
2) Round() function, doesn't round (i mean what calculators do)
I suggest to modify Round() function to:
Result.f = Round(Number.f, [#Decimals])
So
Round(5.56366) would result in 6
Round(5.5) would result in 6
Round(5.4999999) would result in 5
Round(5.56366,3) would result in 5.564
...and if it could be:
Round(5.56366,7) would result in 0.0556366
...
Posted: Sun Mar 20, 2005 4:47 pm
by Kale
What about also adding a flag for rounding up and down?
Round(5.5, #PB_Round_Up) would result in 6
Round(5.5, #PB_Round_Down) would result in 5
Posted: Sun Mar 20, 2005 5:07 pm
by Psychophanta
Kale wrote:What about also adding a flag for rounding up and down?
Round(5.5, #PB_Round_Up) would result in 6
Round(5.5, #PB_Round_Down) would result in 5

Are you joking !?
That's how it works now.
1) the second line is ridiculous because is the
SAME as Int()
2) That's not to
round a number, and that's useless, because Round(5.5, #PB_Round_Up) is
SAME as Round(5.5
+1, #PB_Round_Down) and
SAME as Int(5.5
+1)
Posted: Sun Mar 20, 2005 11:47 pm
by Froggerprogger
There's a difference between Round and Int:
Round returns a float, Int returns an int.
But I'm waiting for a simple 'normal' round (= "Round Half Up"), too.
atm we can use:
Code: Select all
Procedure.f RoundHalfUp(x.f)
If x >= 0.0
ProcedureReturn Round(x + 0.5, 0)
Else
ProcedureReturn Round(x - 0.5, 1)
EndIf
EndProcedure
A further optional parameter for the number of decimals would be pretty cool!
Round (number.f, roundingMode.l, numberDecimals.l)
roundingMode: #Round_Up, #Round_Down, #Round_HalfUp
Posted: Mon Mar 21, 2005 9:13 am
by Psychophanta
Froggerprogger wrote:A further optional parameter for the number of decimals would be pretty cool!
At the moment i use this
Code: Select all
Procedure.f RoundHalfUp(x.f,d.l)
x*Pow(10,d)
If x >= 0.0
ProcedureReturn Round(x + 0.5, 0)/Pow(10,d)
Else
ProcedureReturn Round(x - 0.5, 1)/Pow(10,d)
EndIf
EndProcedure
Posted: Mon Mar 21, 2005 1:27 pm
by Kale
Froggerprogger wrote:There's a difference between Round and Int:
Round returns a float, Int returns an int.
But I'm waiting for a simple 'normal' round (= "Round Half Up"), too.
atm we can use:
Code: Select all
Procedure.f RoundHalfUp(x.f)
If x >= 0.0
ProcedureReturn Round(x + 0.5, 0)
Else
ProcedureReturn Round(x - 0.5, 1)
EndIf
EndProcedure
A further optional parameter for the number of decimals would be pretty cool!
Round (number.f, roundingMode.l, numberDecimals.l)
roundingMode: #Round_Up, #Round_Down, #Round_HalfUp
thats what i meant.

Posted: Mon Mar 21, 2005 1:33 pm
by Froggerprogger
That's what I knew that you meant.
I don't know, if you know, that I know, what you know, you know ? So what do you know now ? That I don't know what you know !

Posted: Sun Mar 19, 2006 2:50 pm
by Rescator
It definetly would be nice if Round() default behaviour was similar to this!
(yeah yeah, I'm pretty sure my ASM is very wrong, but the example works
Code: Select all
Procedure.f froundint(num.f)
Protected result.l
!FLD dword[p.v_num]
!FRNDINT
!FISTP dword[p.v_result]
ProcedureReturn result
EndProcedure
Debug fround(1.4)
Please note, .0 to .499999something is rounded down,
.5 to .9999999something is rounded up.
Posted: Sun Mar 19, 2006 3:00 pm
by DarkDragon
Standard-Round-Arithmetic:
Int(Value+0.5)
Here's my code:
Code: Select all
Procedure.f Round2(Value.f, Deci.l)
If Value < 0 : Value * -1 : b = 1 : Else : b = 0 : EndIf
a.l = Pow(10, Deci)
Result.f = Int((Value*a)+0.5)/a
If b = 1 : Result * -1 : EndIf
ProcedureReturn Result
EndProcedure
Debug Round2( 3.500000, 0)
Debug Round2( 3.499999, 2)
Debug Round2(-3.500000, 0)
Debug Round2(-3.499999, 2)
Posted: Sun Mar 19, 2006 3:11 pm
by ts-soft
@DarkDragon
what is abou this:
gives 3.5 and not 3.0
Posted: Sun Mar 19, 2006 3:31 pm
by DarkDragon
ts-soft wrote:@DarkDragon
what is abou this:
gives 3.5 and not 3.0
second parameter is decimals count
Zweiter parameter bestimmt auf wieviele stellen gerundet wird.
Posted: Sun Mar 19, 2006 4:49 pm
by thefool
Yes, darkdragon i think he knows that. But if you were to round 3.4 what would it give?
Posted: Sun Mar 19, 2006 4:56 pm
by DarkDragon
thefool wrote:Yes, darkdragon i think he knows that. But if you were to round 3.4 what would it give?
No he didn't understand it.
Works, too:
The topic is about Round() makes no sense as it is in PB, because you can specify how to round(up or down).
Posted: Sun Mar 19, 2006 5:10 pm
by thefool
DarkDragon wrote:
The topic is about Round() makes no sense as it is in PB, because you can specify how to round(up or down).
Yes it should have a default mode, where it followed the normal behaviour (eh 3.45=3.5 and so on)..
Posted: Sun Mar 19, 2006 5:17 pm
by DarkDragon
thefool wrote:DarkDragon wrote:
The topic is about Round() makes no sense as it is in PB, because you can specify how to round(up or down).
Yes it should have a default mode, where it followed the normal behaviour (eh 3.45=3.5 and so on)..
Yes like my procedure does

. So 3.4999 will never get 3.4

that would be senseless.