Jump to content

toFixed() with innerHTML

Recommended Posts

I am making a website to get Radio frequencies from Microsoft Flight Simulator through Simconnect on my computer.

I would like to get the FREQ from FSX and convert them to 0, 1, 2, 3 decimal places.

Ill give a example below and explain it.

I want to set COM1 Freq to 3 decimal places 130.250 but where do i put the toFixed(3) at in the code.



Gets COM1 Active frequency from FSX

<SCRIPT src="../jquery-1.7.1.js"></script><script src="sprintf.js"></script>   <script type="text/javascript"></script>
function body_onload() {var jqXHR;jqXHR = $.getJSON("http://" + location.hostname + "/add_definition?definition_name=RADIO&name=COM1_A&PropertyName=COM ACTIVE FREQUENCY:1&UnitName=MHz&DatumType=FLOAT32", function(data) {});}

Sets variable for it

function get_values() {var C1A = document.getElementById("COM1_AD");C1A.innerHTML = definition_data.COM1_A;}

Displays the data

<BODY onload="body_onload()"><P>COM 1 Active  is: <SPAN id="COM1_AD"></SPAN></P></BODY>


Link to post
Share on other sites

I assume definition_data.COM1_A is the variable with the number you want. You can just change the line to

C1A.innerHTML = definition_data.COM1_A.toFixed(3);

If that doesn't work, then it's because it's not a number and you'll have to cast it to a number first:

C1A.innerHTML = Number(definition_data.COM1_A).toFixed(3);
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...