Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Dividing two variables: decimal comma versus decimal point

In my script, I have two variables (A1 and A2). I am calculating a 3rd variable (A3) by summing the first two variables (A1 + A2). I am running into problems with decimal points and comma's.

The variables A1 and A2 are both smaller than 1. Although I have set the decimal separator to be comma (',') in my document, I am using a decimal point for A1 and A2. If I don't do this, A1 and A2 are not being recognized as numbers. When I calculate A3, the result has a comma (',') as decimal separator. Any further calculations using A3 go wrong, presumably because A3 with the decimal comma is not being recognized as a number. Can anybody point out how to solve this?

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Marc, try using this, reading A3 with decimal comma using num#(), and converting to decimal dot using num()

num(num#(A3,'#.###,#'),'#,###.#').

View solution in original post

5 Replies
Not applicable
Author

Hey Marc,

Would it be possible to attach a sample file with some dummy data and the issue you are facing? It would be very helpful in addressing this.

Also where did you set the decimal separator as comma. You can set it only for specific fields. When you put A1 and A2 in a text box do you see comma or decimal point.

Thanks

AJ

Anonymous
Not applicable
Author

Marc, try using this, reading A3 with decimal comma using num#(), and converting to decimal dot using num()

num(num#(A3,'#.###,#'),'#,###.#').

Not applicable
Author

Attached a sample file similar to what you explained. It seems to be working fine. Please take a look at it let me know.

Edit:

Use these as your environment variables:

SET ThousandSep='.';

SET DecimalSep=',';

SET MoneyThousandSep='.';

SET MoneyDecimalSep=',';

SET MoneyFormat='$#.##0,00;($#.##0,00)';

Thanks

AJ

Not applicable
Author

Hi Michael,

Thanks for the answer. This works.

Amazing how some carppy some of the Qlikview scripting language is:

  • Even though you set the decimal seperator to comma, varaiables only work with a decimal point
  • If you do a calculation with the variables, theoutcome has a decimal comma
  • You need to concert the outcome to a numer with a decimal point to be able to use it for further calculations

Anayway, thanks again.

Anonymous
Not applicable
Author

Marc,

I'm glad my suggestions works for you.  My purpose was to make it independent from the environment variables settings.  But AJ proved in his example that there is no problem using comma.  I think something is missing in your situation.

Anyway, whatever it is, you'll be fine.

Regards,

Michael