Is it possible to return a float value with 2 decimal places for 0?

0

I'm doing a push to get fed into Google Analytics and one of the guidelines that prices are returned as float, so that's fine I've managed to solve using parseFloat (), however, they need two decimal places up to values that end with 00. Ex: (100.00 or 208.00). When it returns a float value it removes values that end with 0.

var product_price = “100.00”; value = parseFloat(product_price);    
resultado = 100

I used the .toFixed (2) method to place the two decimal places but return as String.

Well, I've already researched several places and all the solutions I found and the ones I know returno string. I believe that technically it is not possible. But I would like a certainty.

Could you tell me if it is possible to return a value with two decimal places for final values of .00.

Just to make it clear that parseFloat returns a value with a floating point such as 100.99, now for a 100.00 no.

Thank you.

    
asked by anonymous 11.10.2018 / 16:46

1 answer

-1

        var product_price = '100.00';
        var value = parseFloat(product_price).toFixed(2); 
        console.log( value );

In case of to keep everything you have already done and add the method toFixed(x) with the number of decimals you want to have after the point.

    
11.10.2018 / 19:27