0
I am pushing to be fed in Google Analytics and one of the guidelines that the prices are returned as float, so far all well managed to solve using parseFloat(), however, they need two decimals up to values ending with 00. Ex:(100.00 or 208.00). When returns a float value it removes values ending with 0.
var product_price = “100.00”; value = parseFloat(product_price);
resultado = 100
I used the method . toFixed(2) to place the two decimal places but Return to String.
Anyway, I have researched in several places and all the solutions I found and those I know returno string. I believe that technically it is not possible. But I would like a certainty.
They would tell me if it is possible to return a value with two decimal places to final values . 00.
Just to make clear the parseFloat Return a value with floating point as 100.99, now for a 100.00 no.
Thank you.
And what is the problem of sending the string with the decimal part reset? Anyway, regardless of the type you use, Google will receive as string, because the data is sent via HTTP.
– Woss
The reason is just a request from the analyst who takes care of Google Analytics, as I have no knowledge of the tool, I have these doubts. The same reported that if I send a value as a string to Analytics it does not recognize.
– A. G. Araujo
Either it’s float or it’s value ended with zero. It can’t be both. If you explain the real problem, maybe you can help (what is in the question is an artificial requirement, google Analytics does not require "numeric type" with zeros on the right). Read this to understand it better: What is the "X Y problem"
– Bacco
The float is nothing more than the floating point. My doubt is very clear: "They would tell me if it is possible to return a value with two decimal places to final values . 00." I need to convert a string to float and if the value is 100 it needs to return to 100.00 and continue to float. What if that’s possible? Just.
– A. G. Araujo
Only as string. Numerically there is no difference between 100.00 and 100. In this case, the decimals are merely visual and therefore demand to be string.
– Woss
Yes, your doubt is very clear. Only it stems from a lack of understanding on your part. That’s what we’re trying to explain. Let me try to answer it another way: Numerical formatting is only done in string, either directly or indirectly. I hope now you’ve been able to answer your question.
– Bacco
I agree, numerically it makes no difference. I just need to explain to myself technically that this is impossible.
– A. G. Araujo