# How to handle the decimals problem

Hi,
I have a textfield that shows a result after some calculation like 4666.6666.
My problem is that I do not need the “.6666” portion of the result and it must not be rounded up to the nearest number like “4667”
How do I go about doing that?

Regards,
Benny

depends what you need
if you need the string just use left(yourstring, (instr(your string, “.”)) or whatever the separator is in your language
if you need the integer use val(your string) for small integers. For larger numbers there is something else, forgotten what it is

Hi,
I actually need the integer.
The calculation came from somewhere else eg. (3500/30) * 4 = 466.6666
How do I format the textfield that receive the result(466.6666) into 466?

Benny

Use Round()

textfield1.text = str(round(3500/30))

I used Round() but that will round the number to 117. I need the result to be 116.

Thanks

Round follows the rules of rounding. Use Floor to always round down.

Thank you very much!!!

Be aware that if you try Floor( -4666.6666) you’ll get -4667. For negative numbers, you’ll have to use the Ceil() function.
To extract the integer part of a number I’m using the following method:

[code]Function zdInt(inValue As Double) As Double

//-- Return the Integer part of inValue

If inValue < 0 Then

``````//  The value is negative we use Ceil()
Return Ceil( inValue )
``````

Else

``````// the Value is positive ( or zero ), we use Floor()
Return Floor( inValue )
``````

End If

End Function[/code]

If you are trying to do integer math then you might use 3500 \ 30 which is an integer divide.

There’s an old school way of doing it too:

Dim i1, i2, i3 As Integer
i2 = 10
i3 = 3

i1 = ( i2 -(i2 MOD i3)) / i3

Couldn’t tell you if that is more efficient then FLOOR though or possibly what FLOOR is doing under the hood.

Just as a reminder, using the Integer data type sets a limit depending on the build type ( 32/64 bits ). Doing so with values beyond the limits will lead to unexpected results.
See Integer in Xojo’s doc for the Int32 and Int64 limits and the example demonstrating the value overflow behavior.