# spliting number into 2 fields (before and after decimal)???

This topic is 5676 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

Hi All

Can anyone help me.

I want to divide a number (in another field) into 2 new fields. One holding the part of the number before the decimal and another containing only the 2 digits after the decimal.

Have no problem with the first part but if I use a calculation with Round (number; precision) to get the part after the decimal it works fine as long as the number doesn't end with .00

When the number ends with .00 it takes the to digits before the decimalpoint instead of the to zeros after the decimalpoint...

example

This works

number = 1025.95

firste part ok = 1025

second part ok = 95

This doesn't

number = 1025.00

first part ok = 1025

second part fail = 25

Have also tried with truncate instead of round and combinations of both but with no luck...

Also tried to multiply the number with 1.0001 to get a number I knew had more decimals but... still same result.

Any help would be great

Best regards

The Dog

Edited by Guest
##### Share on other sites

Grab integer:

Int(numberfield)

Grab remainder and remove decimal point:

Substitute(Mod(numberfield, 1), ".", "")

##### Share on other sites

Hi John

Tried making a field with the calculation

(Field=)

Substitute(Mod(ORDRE::TOTAL, 1), ".", "")

But I get an error telling me that the field does not exist.

Found out that there were 2 "," that needed to be changed to ";"

So now I'm using

(Field=)

Substitute(Mod(ORDRE::TOTAL, 1); "."; "")

and it works fine. But I still have a little problem.

It only shows 5 if the remaining decimals is .50

Would like it to show to digits everytime.

As if

.50 = 50

.05 = 05

.25 = 25

So I still need a little help.. Sorry ;o)

Best regards

The Dog

Edited by Guest
##### Share on other sites

Try this, for the remainder:

Middle ( GetAsText ( number ) ; Position ( GetAsText ( number ); "." ; 1 ; 1 ) + 1 ; 2 )

Note that this calc works with FM8...

the GetAsText function may have another name in FM6 (now I don't remember)

##### Share on other sites

The simplest way is to format the field's display as decimal number with fixed 2 decimal digits. You can do this by selecting the field in Layout mode, and choosing Format > Number... from the menu.

If, for some reason, you need this as a calculation, you have to round the number first. Because 1.996 should come out as 2.00. Rounding also makes it easier to extract the remainder:

Int ( Round ( Number , 2 ) )

& "." &

Right ( "00" & Round ( Number , 2 ) * 100 , 2 )

##### Share on other sites

Hi raybaudi

But there is no GetAsText in filemaker 6.. ;-(

##### Share on other sites

Hi comment

he has an international copy of FM6, so ',' must be changed into ';'

##### Share on other sites

try something as:

NumberToText..

##### Share on other sites

Hi Comment

It solved my problem... Thanks a lot..

and to raybaudi Thanks too..

##### Share on other sites

Good.

BTW, Daniele: most of the time, you don't need to convert data type explicitly. Filemaker does that for you on-the-fly, so for example:

Position ( number ; string ; 1 ; 1 )

is automatically interpreted as:

Position ( GetAsText ( number ) ; string ; 1 ; 1 )

without you having to write it out.

Same goes for setting the result type of a calculation. For example, try a calculation of Get (CurrentDate), but set the result to Number.

Then see what happens with MonthName (732444).

Edited by Guest
##### Share on other sites

Thank you comment

##### Share on other sites

This topic is 5676 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account