Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
katkaKF
Contributor II
Contributor II

How to calculate variables if decimal separator is set to comma

Hi,

in my environment is decimal separator set as comma and I have problem with number variables. I created new QVW file, where I created new variable and displayed its value in Text Object:

SET ThousandSep=' ';
SET DecimalSep=',';
SET MoneyThousandSep=' ';
SET MoneyDecimalSep=',';
SET MoneyFormat='# ##0,00 €;-# ##0,00 €';

LET vTest = 1/10;

I have in in TextObject:

=$(vTest)

But it isn't displayed, I have an error: "Error: Garbage after expression:','". What did I wrong? If I change decimal separator in load script to dot (SET DecimalSep='.';), it works properly. Why is the result influenced by setting of the decimal separator? I thought, that DecimalSep is just a format that is used to display the value and not to evalueate it. I thought it has no effect during the calculations of the value.

If I have in load script SET DecimalSep=','; and in TextObject = num(vCoef, '#,##', '.', ','), it is displayed properly.
Does it mean, that I have to always use NUM function during calculations with variable, when I have decimal separator set to comma?

Thanks

Katka

2 Solutions

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

hi 

try this first 

in the title of the slider write : =vCoef 

and in the chart 

SUM(UnitCost * UnitsBalance) + vCoef * (SUM(UnitCost * UnitsBalance))

View solution in original post

lironbaram
Partner - Master III
Partner - Master III

hi 

the $(vCoef) calls for a calculation as variables might hold expressions or mathematical functions 

if the variable is a number than you don't need the $ sign 

 

View solution in original post

5 Replies
lironbaram
Partner - Master III
Partner - Master III

hi

if your variable is a static number 

you can use =vTest

and if you have a formula you can for example sum(value*vTest)

katkaKF
Contributor II
Contributor II
Author

Hi

I just want to know, whether it is necessary to know in the beginning of the creating the new project what number format will be used.

Has the setting of decimal separator influence of the way, how to work with variables? I think that is just a formatting matter and has no impact on the codeing. Am I wrong?

I have a Slider Object with variable.  I have in script:

SET DecimalSep=',';

vCoef = 0;

In Slider Object I set this variable and on the Caption Tab I have Title Text:

=$(vCoef)

In the Chart I have What If expression set to:

SUM(UnitCost * UnitsBalance) + $(vCoef) * (SUM(UnitCost * UnitsBalance))

In variable overwie I can see, that the variable vCoef is set to 2,3 instead od 2.3 and int the title bar of slider is an error: "Error: Garbage after expression:',' " and the What If column in the chart is empty: SliderObject3.png

When I manualy change setting of the constant DecimalSep to dot:

SET DecimalSep='.';

it works.  It also works, if I replaced vCoef with = num(vCoef, '#,##', '.', ',') and everything is correct, but I dont think that it is what I should do. Or is it?

Should I always use NUM if I work with calculated variable and DecimalSep is comma?

Thanks

Katka

lironbaram
Partner - Master III
Partner - Master III

hi 

try this first 

in the title of the slider write : =vCoef 

and in the chart 

SUM(UnitCost * UnitsBalance) + vCoef * (SUM(UnitCost * UnitsBalance))

katkaKF
Contributor II
Contributor II
Author

Hi

that works, wow!

But I am confused now, what is the difference between vCoef and $(vCoef)? What does it mean, that it is static number? I thought, that static number means, that it is a constant. In slider object the value of this variable is changing, and despite that is it a static number? 

Thanks

 

lironbaram
Partner - Master III
Partner - Master III

hi 

the $(vCoef) calls for a calculation as variables might hold expressions or mathematical functions 

if the variable is a number than you don't need the $ sign