I have a Global: Maths Field pulling from another field in order to perform simple arithmetic...

[total_amount]-[expression_1]

[total_amount] is being pulled in from a database and [expression_1] is another maths field. The latter maths field pulls in fine but the first does not.

Tried multiple combinations but no dice. Any suggestions why a maths field does not pull in data from preceeding fields?

Comments

lionsharz’s picture

Ah! I think I discovered why. The field being pulled in contains a currency symbol (€100) so its not just numbers. It feeds to a custom test field ok.

Anyone got any advice on how to strip out that currency symbol? Or rewrite the output of the field somehow?

merlinofchaos’s picture

Status: Active » Fixed

The simplest, if not very elegant way to achieve this is to make an alternate version of the field that is set to 'exclude' so it doesn't display, and turn off all formatting so that you get a raw number.

lionsharz’s picture

Yep - that did the trick. Ran into a similar problem with the maths field becoming confused by civicrm's thousand separater (comma by default - and cannot be blank) Used this method for that too.

EDIT
Unfortunately I've double checked and this didn't work as I originally thought. The output in the custom maths field still contains the comma. It is simply feeding in the raw output of the original field and outputting it the same way.

I don't know how to "unformat" or otherwise remove the comma. Any ideas?

lionsharz’s picture

Status: Fixed » Active
lionsharz’s picture

...the 'source' field (where the data gets fed in first) is being pulled in from civicrm. Unfortunately there is no option to remove the thousand separator (you can use either a comma or a space) there in civi. So whatever happens the field is going to contain this output with the comma.

This is going to throw the Global: Maths field as it only recognizes the first number up to the comma or space.

Therefore, I think I need something that will re-write the output in a conditional way, like if the number contains a space and/or comma, then strip these out and leave the number only.

Maybe there's a module for s'thing like this... conditional text formatting or similar...(?)

lionsharz’s picture

Hi

I know this is old but can anyone help me out with this? I have to revisit the issue now and I can't figure out how to convert currencies into numbers.
Maybe it could be done with a simple PHP string...?

Any pointers much appreciated :)

mustanggb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closing this as outdated to tidy up a bit around here. If you're still having problems with the latest release please create a new issue.