-2

Have ([Name-Width]*.0393701).toFixed(4); so far

The [Name-Width] pulls a hsize from a XML XPath then converts that value from millimeters to inches to the fourth decimal point.

Now I need to get a result that makes it looks nice.

Examples:

5.1250 = 5.125

5.0625 = 5.0625

5.2500 = 5.25

5.0000 = 5

5.5000 = 5.5

Hope you guys can help.

BlueEyesWhiteDragon
  • 427
  • 1
  • 6
  • 20
Patrick
  • 9
  • 1
  • 1
    This might help you http://stackoverflow.com/a/3613112/597419 – Danny Jul 22 '14 at 16:38
  • Hi again Guys. I'm a complete virgin to JavaScript. I need to know what to copy and paste into my existing code. Below what I already have. My brain is already fired :) – Patrick Jul 22 '14 at 16:48

1 Answers1

2

Try converting it to string! That won't show any extra zeros!

var one = 5.1250;
one.toString();

(one = 5.125)

Hope this helps

EDIT: Assigning it to a new var would be better practice

var one = 5.1250;
var one_nozeros = one.toString();

EDIT: Try this for XML?

var one = (<r><![CDATA[

The text string goes here.  Since this is a XML CDATA section,
stuff like <> work fine too, even if definitely invalid XML. 

]]></r>).toString();
BlueEyesWhiteDragon
  • 427
  • 1
  • 6
  • 20
  • Hi again Guys. I'm a complete virgin to JavaScript. I need to know what to copy and paste into my existing code. Below what I already have. My brain is already fired :) – Patrick Jul 22 '14 at 17:01
  • I still don't understand? My results from the first line of my script always gives me different results from the XML file I'm choosing. Please be patient w/ me – Patrick Jul 22 '14 at 17:07
  • var inches = ([Name-Width]*.0393701).toFixed(4); var inches_nz = inches.toString() Returned No RESULTS – Patrick Jul 22 '14 at 17:16
  • Now I'm completely lost... – Patrick Jul 22 '14 at 17:24