Side by Side Ignoring Decimals | XM Community
Skip to main content
Solved

Side by Side Ignoring Decimals

  • August 3, 2023
  • 3 replies
  • 35 views

Forum|alt.badge.img+2

I have a side-by-side table that calculates inputs and provides a total. What I can’t seem to get to work is the ability to calculate decimals. It always seems to ignore it. I’ve been trying to replace: 


function getVal(val){ var num = parseInt(val); if(isNaN(num)) {num = 0;} return num;};

 

With both: 
function getDouble(val){ var num = parseInt(val); if(isNaN(num)) {num = 0;} return num;};
function getFloat(val){ var num = parseInt(val); if(isNaN(num)) {num = 0;} return num;};
 

But it will still treat the inputs as integers or completely break and cause the side-by-side to do nothing. 

A lot of my code is from a user named bstrahin in their post linked here: 

The only difference is that I’m multiplying between two columns, the color changes depending on the value for the grand total, and I have two different grand totals. Any help will be greatly appreciated, as I can’t determine why this issue occurs.

 

 

Best answer by rgupta15

Something like below

function getFloat(val) { var num = parseFloat(val); // Use parseFloat to handle decimal values if (isNaN(num)) { num = 0; } return num; }

 

3 replies

rgupta15
Level 4 ●●●●
Forum|alt.badge.img+8
  • Level 4 ●●●●
  • 92 replies
  • August 10, 2023

parseInt seems to be the issue. Use the float type instead.


rgupta15
Level 4 ●●●●
Forum|alt.badge.img+8
  • Level 4 ●●●●
  • 92 replies
  • Answer
  • August 10, 2023
Something like below

function getFloat(val) { var num = parseFloat(val); // Use parseFloat to handle decimal values if (isNaN(num)) { num = 0; } return num; }

 


Forum|alt.badge.img+2
  • Author
  • 1 reply
  • August 10, 2023
Something like below

function getFloat(val) { var num = parseFloat(val); // Use parseFloat to handle decimal values if (isNaN(num)) { num = 0; } return num; }

 

I’m so upset that I wasn’t able to notice the “parseInt” in my “function getFloat” and “function getDouble”

Thank you for pointing it out to me!