admin管理员组文章数量:1391960
I'm using oracle apex version 20.1 and I can not get past this weird javascript error. I have a dynamic action that populates a page item (P616_FRM_AMT2) based on the getValue() of another page item (P616_TO_AMT1) with a little addition inside the setValue() function. The result i'm trying to achieve in this example is 10.01. The problem in the code is pretty self explanatory, can someone explain how this is possible?
// Get value of first page item
to_amt = apex.item( "P616_TO_AMT1" ).getValue(); // returns 10
// Examples of using arithmetic in the .setValue() working correctly
apex.item("P616_FRM_AMT2").setValue(to_amt/10); // returns 1
apex.item("P616_FRM_AMT2").setValue(to_amt*10); // returns 100
apex.item("P616_FRM_AMT2").setValue(to_amt-1); // returns 9
apex.item("P616_FRM_AMT2").setValue(to_amt-1.01); // returns 8.99
// Using addition in the .setValue()
apex.item("P616_FRM_AMT2").setValue(to_amt+1); // returns 101
// What I actually need to do
apex.item("P616_FRM_AMT2").setValue(to_amt+.01); //returns 100.01
// Had to add this edit because it changes my question, addition works with ONLY static values?
apex.item("P616_FRM_AMT2").setValue(10+.01); //returns 10.01
I'm using oracle apex version 20.1 and I can not get past this weird javascript error. I have a dynamic action that populates a page item (P616_FRM_AMT2) based on the getValue() of another page item (P616_TO_AMT1) with a little addition inside the setValue() function. The result i'm trying to achieve in this example is 10.01. The problem in the code is pretty self explanatory, can someone explain how this is possible?
// Get value of first page item
to_amt = apex.item( "P616_TO_AMT1" ).getValue(); // returns 10
// Examples of using arithmetic in the .setValue() working correctly
apex.item("P616_FRM_AMT2").setValue(to_amt/10); // returns 1
apex.item("P616_FRM_AMT2").setValue(to_amt*10); // returns 100
apex.item("P616_FRM_AMT2").setValue(to_amt-1); // returns 9
apex.item("P616_FRM_AMT2").setValue(to_amt-1.01); // returns 8.99
// Using addition in the .setValue()
apex.item("P616_FRM_AMT2").setValue(to_amt+1); // returns 101
// What I actually need to do
apex.item("P616_FRM_AMT2").setValue(to_amt+.01); //returns 100.01
// Had to add this edit because it changes my question, addition works with ONLY static values?
apex.item("P616_FRM_AMT2").setValue(10+.01); //returns 10.01
Share
Improve this question
edited Aug 16, 2022 at 20:08
LogicallyFunky
asked Aug 16, 2022 at 18:50
LogicallyFunkyLogicallyFunky
771 silver badge15 bronze badges
1 Answer
Reset to default 4First check what getValue() actually returns:
Looks like the javascript variable is a string
Now take apex out of the equation and check what javascript does with numbers vs strings when doing "+.01".
There you go, this is how javascript handles it. You're relying on implicit conversion in javascript, assuming that it will handle that correctly. I think you will find the answer in javascript forums if you really want to know why this exact behaviour happens. Or just do the conversion yourself to avoid any confusion...
本文标签: javascriptapexitem()setValue() does not work with additionStack Overflow
版权声明:本文标题:javascript - apex.item().setValue() does not work with addition? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744700312a2620525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论