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

Numbers with 2 decimal digits (Javascript)

Contributor ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

...

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 !...

😉

...

Views

369

Translate

Translate

Report

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
Contributor ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

...

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 !...

...

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
Contributor ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

LATEST

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

Merci Lily !...

Votes

Translate

Translate

Report

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