With Java-Script problems

Roman Chijner shared this question 6 years ago
Answered

Hi,

With Java-Script problems

Where the mistake?

Roman Chijner

    a1=ggbApplet.getValue('a1');

    a2=ggbApplet.getValue('a2');

    a3=ggbApplet.getValue('a3');

    ggbApplet.evalCommand('M1='+a1+'' );

    ggbApplet.evalCommand('M2='+a2+'' );

    ggbApplet.evalCommand('M3='+a3+'' );

1acd26c67ac139293db6c2319e504e30

Comments (6)

photo
1

Hi, the problem is that a2 yelds : 5e-7 (try alert(a2+'');) and if you write M2=5e-7 then you have what is displayed : 5 exp(1)-7

A workaround for the moment : use .substring(4) that delete the 4 first characters : <a><2><space><=> from a2 = 0.0000005

    a1=ggbApplet.getValueString('a1').substring(4);

    a2=ggbApplet.getValueString('a2').substring(4);

    a3=ggbApplet.getValueString('a3').substring(4);

    ggbApplet.evalCommand('M1='+a1);

    ggbApplet.evalCommand('M2='+a2 );

    ggbApplet.evalCommand('M3='+a3 );

Cheers. Michel

photo
1

@ Michel

Thank you for your prompt reply .Now I understand the origin of the numbers.


In the representation of numbers,

Can you, please, explain the meaning of the substring(4) (e g why not substring(5) ? or 6 ...) (a2=15*10^(-12 ))

...that delete the 4 first characters : from this number? or from name: <a> <2> <space> =

If the number (e.g. a=12* 10-7) is calculated in the Jscript -how it can be displayed? (With  alert(...+'') is OK!)

Thanks for your help. Roman Chijner

photo
1

var a="01234567"

a.substring(4) yelds : "4567" ,

this command let us keep the part of the string from the index 4 to the end (knowing that the first index is 0).

photo
1

Hi,

@ Michel thanks again

I have a little the same problem

Let in the j-script (as a result of the calculations) is the number abs(r2)<10^(-6).

How can it be added to a GGB file?

Roman Chijner

    r1=1.000000001234567812345

    r2=0.000000001234567812345


    alert('r1=1.000000001234567812345→'+r1+'\n'+'r2=0.000000001234567812345→'+r2)


    ggbApplet.evalCommand('r1='+r1);

    ggbApplet.evalCommand('r2='+r2);

7506c296c210051b45f8ea8d4c3f1b63

photo
1

This should be more robust:

a1 = (a1+"").replace("e","E")

a2 = (a2+"").replace("e","E")

a3 = (a3+"").replace("e","E")


as 5E-7 is correct in GeoGebra, JavaScript gives 5e-7 (by default, but understands 5E-7 too)

photo
1

@Michael Borcherds

Thank you very much. Works !!!

Pity that “e“ and „E“ are not synchronized


I think it will be convenient to use the function

    function noo(a) {

    return (a+'').replace('e','E');

    }

    r1=1.000000001234567812345

    r2=0.000000001234567812345

    ggbApplet.evalCommand('r1='+noo(r1));

    ggbApplet.evalCommand('r2='+noo(r2));

© 2020 International GeoGebra Institute