Anyone know why the 0.00 is showing as .00 ?
# suitescript
c
Anyone know why the 0.00 is showing as .00 ?
a
nope, but ugly fix off the top of my head... just force add leading string zero to everything, and then parseFloat 🙂 on the resulting string.
c
Do you want to see an even uglier fix?
a
YES
I'm so here for that!
c
Old code: if (!amount || amount === 0) { continue; } New code if (!amount || amount == 0) { continue; }
facepalm 1
spot the difference
a
does ".00" == 0?
lol js type things
at least add a comment 😄 that's an awful bugfix
c
=== is veyr strict
== is a bit wider 😄
a
i know that, but i didn't think it would be wide enough to assume a string starting with a non-numeric value could be parsed as a number
my IDE complains about == and != so if I need to effectively do that kind of comparission, I do it explicitly in my code by doing a conversion
c
lol
The real issue is that 0.00 is coming back as .00 from the saved search.
a
can you at least not use
Copy code
if( !amount || parseFloat(amount) === 0 ) continue;
should be fine that's effectively what == is doing here anyway
c
I assume parseFloat(".00") returns 0.00 ?
a
i didn't realize pasrseFloat(".00") === 0
c
that's better than == 🙂
a
c
That's fine, this whole script hinges on if (amount > 0) {
a
it would only return 0.00 if you toFixed(2)
c
which clearly fails int he .00 scenario
but 0 is fine
I need to test that with other values too
👍 1
as everything will hit that parseFloat
a
i assume they're all numbers though right? or null?
parseFloat should be fine?
but yeah test it 😄
b
you need to actually test strings
getValue returns strings, its not returning 0, its returning '.00'
c
why is it returning .00?
when the value in the UI is 0.00 on the search?
b
same reason it ignores the ui formatting preferences
whatever is converting the number 0 to the string .00 is not the same code that is being used in the ui
c
.00 feels like something that's never useful.
I don't know why that's considered desirable as a return value for 0
or 0.00
a
its a currency field?
c
I assume it's a currency field, it's the cogsamount
a
probably something dumb NS is doing... removes leading zeros first... THEN converts toString().toFixed(2) ?
works fine for every value other than 0 😂 ¯\_(ツ)_/¯
c
1.00 all good 0.00 enjoy your type errors
Quote from Evan Goldberg... probably
😂 1
a
no type errors are for closers, sell more, don't have 0s
c
parseFloat seems ok, can't get it to fail.
👍 1
b
you have to keep in mind that the backend is java, so the answer is probably something like their DecimalFormat uses "#.00" as the pattern, with the # denoting an optional digit
this 1
r
Not sure it will be a better solution, but below is another solution you could have done Using a formul field such that if the value is 0 return 0 otherwise return the value. And this is optional in your code you could replace if the value is ===0 with 0.00 if required.
c
I went with the parseFloat() solution
👍 1
I couldn't come up with a failing test case.