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

having trouble with parseFloat

New Here ,
Mar 20, 2019 Mar 20, 2019

So im writing a script and im having trouble converting a variable into a number.

the relevant parts of the code are as follows,

    var cutHeight = sz.add('edittext',undefined,"123.825"); 

    cutHeight.characters = 8; 

    var layFlatWidth = (slitWidth.text - 4) / 2;

    var XX = sz.add('statictext',undefined, "Intials");

        XX = sz.add('edittext',undefined, "");

        XX.characters = 3;

    var repeat = cutHeight;

    var repeat2 = (repeat*25.4)

    var LF = win.add('group');

    var layflat = LF.add('statictext', undefined, "Postition of Fold from the left in mm");

    var LFdistance = LF.add('edittext',undefined,"50");

    LFdistance.characters = 8;

    

    var wMargin = win.add ('group');

    wMargin.alignChildren = 'left';

    var marginLeft = wMargin.add('statictext', undefined,"column gap size in mm");

    var  marginLeftSize =wMargin.add('edittext',undefined,"3.175");

    marginLeftSize.characters = 8;

    var hMargin= win.add('group');

    hMargin.alignChildren = 'right';

    var marginRight = hMargin.add('statictext',undefined,"repeat gap size in mm");

    var marginRightSize= hMargin.add('edittext',undefined,"3.175");

    marginRightSize.characters = 8;

     var marginRightSize = parseFloat(marginRightSize)+parseFloat(repeat2);

var sizeInfo = dimL.textFrames.add();

    sizeInfo.contents =       

        'Slit Width: ' + slitWidth.text + 'mm (' + parseFloat(slitWidth.text/25.4).toFixed(3) +'\") \n' +

        'Print Width: ' + (slitWidth.text - 2) + 'mm (' + parseFloat((slitWidth.text -2)/25.4).toFixed(3) +'\") \n' +

        'Cut Height: ' + (repeat*25.4).toFixed(3) + 'mm (' + parseFloat(repeat).toFixed(3) + '\") \n' +

        'Lay Flat Width: ' + (slitWidth.text-8)/2 + 'mm' + '  (' + parseFloat(((slitWidth.text-8)/2)/25.4).toFixed(3) + '\')'+ '\n' +

        'Repeat Gap: .125"' +  '\n'+

        '(' +parseFloat(repeat*25.4).toFixed(3)  +'mm -' +marginRightSize.toFixed(3)+'mm ) \n' +

        'Column Gap: .125"'  + '\n' +

        '( ' + parseFloat(slitWidth.text).toFixed(3) +'\mm - ' + parseFloat(slitWidth) + 'mm) \n';  

I keep getting NaN for marginRightSize and marginLeftSize+slitWidth.

What am I doing wrong here? how can I fix this?

TOPICS
Scripting
1.1K
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

correct answers 1 Correct answer

Community Expert , Mar 20, 2019 Mar 20, 2019

you need to convert your text fields to numbers

Number(marginRightSize.text)

Translate
Adobe
Contributor ,
Mar 20, 2019 Mar 20, 2019

var marginRightSize= hMargin.add('edittext',undefined,"3.175");

marginRightSize.characters = 8;

var marginRightSize = parseFloat(marginRightSize)+parseFloat(repeat2);

So, marginRightSize is a variable under which you store the edittext field - it isn't the content inside. To get the content inside, you'll have to use marginRightSize.text
Also you have already declared marginRightSize 2 lines above, so there is no need to use "var" again.

var marginRightSize= hMargin.add('edittext',undefined,"3.175");

marginRightSize.characters = 8;

marginRightSize = parseFloat(marginRightSize.text)+parseFloat(repeat2);

In your code i can't find any place where you try to parse marginLeftSize.

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
New Here ,
Mar 20, 2019 Mar 20, 2019

    var wMargin = win2.add ('group');

    wMargin.alignChildren = 'left';

    var marginLeft = wMargin.add('statictext', undefined,"column gap size in mm");

    var  marginLeftSize =wMargin.add('edittext',undefined,"3.175");

    marginLeftSize.characters = 8;

    marginLeftSize = parseFloat(marginLeftSize);

    var hMargin= win2.add('group');

    hMargin.alignChildren = 'right';

    var marginRight = hMargin.add('statictext',undefined,"repeat gap size in mm");

    var marginRightSize= hMargin.add('edittext',undefined,"3.175");

    marginRightSize.characters = 8;

    marginRightSize = parseFloat(marginRightSize.text) +parseFloat(repeat2);

updated code. it is still throwing out NaN where the number is displayed

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
New Here ,
Mar 20, 2019 Mar 20, 2019

I have added .text to leftsize as well now

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 ,
Mar 20, 2019 Mar 20, 2019
LATEST

you need to convert your text fields to numbers

Number(marginRightSize.text)

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