Search code examples
infopath

Splitting number into groups


I'm trying to do a formula in Infopath:

Say i have 3 fields called singles, 10's and 25's.

I also have another field where the user typed in a number.

If the user types in 15 for example, this should fill in the 10's filed with 1, and the singles field with 5.

If the user typed 49 into the field, then the 25's would be filled with 1, the 10's with 2, and the singles with 4.

If they type in 50, then the 25's field will be filled with 2.

Does anyone have any idea where I could start in doing this?

Many thanks in advance.

Jason


Solution

  • Here is the basics of the solution (which was quickly verified in IP). I leave the math specifics up to you just in case this is a HW problem. If you have specific troubles post back and we can help.

    Set a rule on your input field with no conditions so it will fire anytime the field changes.

    Use the number function on a field to be able to use it in calculations. Infopath doesn't have a mod function so do divide with floor and subtraction.

    Create an action for each amount (making sure to order them by highest first).

    So for example your 25s field action would be floor(number(inputfield) / 25).
    Your 10s action would be floor(number(inputfield) - number(25sfield) * 25) / 10).
    Etc for each one (and note that the ones field is just whatever is leftover - no divide or floor needed).