Jump to content

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


The Dog
 Share

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
Link to comment
Share on other sites

Hi John

Thanks for your reply

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
Link to comment
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)

Link to comment
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 )

Link to comment
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
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.