# Global math expression in a views

I added a global math expression field to a views(table display) i just want to sub two fields values,but the the result it's not exact what i want.
Example for that(9000 - 5000 = 4).
How can i change the format or something like that to convert the result to 4000?
Thanks. • I have tried every which way from Tuesday to replicate your results and just can't. Can you give any more information, eg, the fields and the exact text you are putting in this field? – Jimajamma Apr 15 '12 at 4:39
• the two field in my content type is float i just want to make a math operation on these fields, foe example i want to add the two values inside the fields for every row node 1 (field a ) + node 1 (field b) ----- node 2 (field a ) + node 2 (field b) but the result is not what should be, if 5000 + 4000 = 9 not (9000). in global php field i wrote this f= [field_bt_total] +[field_pa_total]; – abd Apr 15 '12 at 4:47

## 3 Answers

Your problem is the number format of your fields. Turn off the comma that delineates thousands.

• This is the correct answer. Views is running the maths evaluation against the string representation of your numbers; (string)4,000 + (string)5,000 = 9 and (string)5,000 + (string)1,0000 = 1. – Chris Burgess Feb 3 '14 at 4:21

You should only need to have `[field_bt_total] + [field_pa_total]` in there--nothing else (no f=, no ;)--and that should produce `9000` as the result....assuming of course your `field_bt_total` really does equal `5000` and your `field_pa_total` really does equal `4000.`

• it's not work for me just showing 6.00 as result for 5000 + 1000 – abd Apr 15 '12 at 5:39
• so, if you were to put `5000 + 1000` in the field, it prints out `6.00`? – Jimajamma Apr 15 '12 at 5:43
• yes it is, where is the problem :( – abd Apr 15 '12 at 5:45
• the only thing I can suggest at this point is to create some screen shots as none of this makes much sense – Jimajamma Apr 15 '12 at 5:47
• It makes perfect sense if you know that Views is running maths on text formatted numbers, see @user1195936 answer. – Chris Burgess Feb 3 '14 at 4:22

As an alternative, you could consider to use the Computed Field module to compute the value, so you can simply add the result to your view just like any other field.

• the problem is i want to add two fields from two different content types(one referenced to another), so i can't use computed field, – abd Apr 15 '12 at 20:40
• I see, that makes it more complicated. Still, it should be possible to retrieve the referenced node in the computed field code to get the value you're looking for. – marcvangend Apr 16 '12 at 8:08