Page 2 of 2

Re: Rounding to two decimal places without Round

Posted: Saturday 3rd June 2023 5:43pm
by gambafeliz
BruceSteers

I was done the same, was used string functions. That's why you ask the question. :)

On the other hand, Cogier you have managed with your last reflection to make my neurons a mess. But what question are you asking?

Re: Rounding to two decimal places without Round

Posted: Sunday 4th June 2023 1:39pm
by cogier
On the other hand, Cogier you have managed with your last reflection to make my neurons a mess. But what question are you asking?
Sorry, I was not trying to fry your brain! :D

The purpose of Int is to create an Integer. So how can it return a Float?
The difference between Int() and CInt() is:

Int() may return a Float value, CInt() is limited to 32 bit Integer.
Int() rounds to the next lower value. i.e. -4.6 to -5, while CInt rounds towards 0 i.e. -4.6 to -4

Re: Rounding to two decimal places without Round

Posted: Sunday 4th June 2023 6:21pm
by vuott
cogier wrote: Sunday 4th June 2023 1:39pm The purpose of Int is to create an Integer. So how can it return a Float?
Uhmmm... perhaps the question should be put in Gambas "Mailing List".

Re: Rounding to two decimal places without Round

Posted: Monday 5th June 2023 11:42am
by thatbruce
Int() can return a float value because...
Dim fNum as Float
fNum=Int(1.234)
Print fNum

1.0000

whereas

Dim fNum as Float
fNum=CInt(1.234)
Print fNum

!@OUrg Expected float got Integer

What is misrepresented here is f(x) returns a value that can be interpreted as a variable on the left hand side of the assignment and therefor be a valid assignment.
Think this way, if fNum was a Float[] then you would not expect fNum=Int(1.234) to work but fnum=[Int(1.234)] should. There are many similar cases where the assignment could be misunderstood as being a nonnegotiable translation but in fact they are. One of the beauties of this is that an Object can in fact be anything so if the assignee is an object then the assignment can work.

Re: Rounding to two decimal places without Round

Posted: Monday 5th June 2023 2:17pm
by cogier
thatbruce wrote: Monday 5th June 2023 11:42am
What is misrepresented here is f(x) returns a value that can be interpreted as a variable on the left hand side of the assignment and therefor be a valid assignment.
Think this way, if fNum was a Float[] then you would not expect fNum=Int(1.234) to work but fnum=[Int(1.234)] should. There are many similar cases where the assignment could be misunderstood as being a nonnegotiable translation but in fact they are. One of the beauties of this is that an Object can in fact be anything so if the assignee is an object then the assignment can work.
I can't get my head around this. My brain hurts now. :?