Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Numbers with 2 decimal digits (Javascript)

Engaged ,
Nov 10, 2020 Nov 10, 2020

...

Hello Captivaters !...

I have a Javascript issue... I'm working on the division with decimal numbers...

So far my script 1 is :

window.cpAPIInterface.setVariableValue("VD_1", Math.floor(Math.random()*800+200)/100);
var V_1 = VD_1.toLocaleString("fr-FR");
window.cpAPIInterface.setVariableValue("V_2", Math.floor(Math.random()*8)+2);

 

Then I have Expression => VD_R = VD_1 * V_2

 

And my sript 2 is :

var V_R = VD_R.toLocaleString("fr-FR");

 

And eveything seems to be ok :

Division_01.png

But sometimes this is what happen :

Division_02.png

So I need the V_R variable to display 2 decimal digits !...

I have tried :

V_R.toFixed(2)

After the first line of my script 2... But it doesn't seem to resolve this...

 

So your help is required !...

😉

...

649
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 10, 2020 Nov 10, 2020

...

I answer myself as I believe I found a solution...

In fact it appears that the method "toFix" is not compatible with the function "toLocaleString" !!!...

So I had to put this :

var V_R = VD_R.toLocaleString("fr-FR", {minimumFractionDigits: 2});

And it seems to be ok !...

...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2020 Nov 10, 2020
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 10, 2020 Nov 10, 2020
LATEST

"C'est l'intention qui compte !..."

Merci Lily !...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources