How to print decimal numbers only when the digit after decimal point is numbers except 0?

I want to make a function that prints accurate result(including the numbers after decimal) when the right value after the decimal is anything but 0.

For example,

if num = 5.9999947575, return 5.9999947575
if num 50000.0000, return 50000
if num = 500.0000023, retutn 500.0000023
if num 7215.22152790009999, return 7215.22152790009999
if num = 1000.0000 return 1000

Please help me!

There might be a much simpler way, but I would write a function that turns the number into a string, loop through each character, if it is after the decimal point, and not a zero, round it off.

I also read read somewhere that you can split the number in two parts one before the decimal and one after the decimal. Then you can check the right values of the decimals for the zeros. But its not working

show your code - so we can see what’s not working

If this is JS, it will do that anyway, can you explain what issue you’re having in a bit more detail?

> 50000.0000
50000
> 5.9999947575
5.9999947575
> 500.0000023
500.0000023

That’s JavaScript, just pasting the numbers into the console.

http://www.codewars.com/kata/57e93e4a2aee4974d4000c2f/train/javascript

This is the link to the problem I wanted to solve.

This is my code:

function vestBuy(price, haggle){
  switch (haggle) {
    case 'light':
      price -= 0.2 * price;
      return price;
      break;
      
    case 'medium':
      price -= 0.3 * price;
      return price;
      break;
      
    case 'heavy':
      price -= 0.4 * price;
      return price;
      break;
      
    case 'walkandswear':
      price -= 0.9 * price;
      return price;
      break;
      
    default:
      return 'Run!!';
    }
}

The problem is when the returned price (answer) is in natural numbers, it works fine.
But when the returned price is a float (say 502.1489), the output gets rounded off (it becomes 502).
I want the output price to be what it is when it is in float( exact 502.1489). But if the output is (502.0000) I want it to be 502.
In simple terms, only shorten it when the decimal values are 0 else keep the way it is.

Please let me know if you guys understand me. I will explain my problem again if you want.

Yeah, sure. The problem is when the returned price (answer) is in natural numbers, it works fine.
But when the returned price is a float (say 502.1489), the output gets rounded off (it becomes 502).
I want the output price to be what it is when it is in float( exact 502.1489). But if the output is (502.0000) I want it to be 502.
In simple terms, only shorten it when the decimal values are 0 else keep the way it is.

I also uploaded my code below.

Is there more code than this? Because nothing there is rounding anything - how is 502.1489 coming out as 502? Also, surely 5.9999947575 can’t be a valid answer, as it specifies that the answers have to be in Rupia?