I'm encountering an issue with ״rounding error״ wh...
# general
x
I'm encountering an issue with ״rounding error״ when trying to save a sales order in NetSuite using SuiteScripts. The error occurs when trying to save a decimal number with 2 or 3 digits after the decimal point. Strangely, this issue only occurs in our production environment and not in our sandbox. We've tried reducing the number of digits after the decimal point to 2, but the error persists. We're using the exact same scripts in both our production and sandbox environments, so we suspect that this may be a problem with the configuration of NetSuite. We're unsure what may be causing this problem, so any help or insights would be greatly appreciated. Thank you in advance! Edit:This is the error we are getting: "Rounding Error: 14973.75", where "14973.75" is the "taxtotal" value - so we suspect it's a problem with the "taxtotal" field. Here are all the fields we are setting values to (in order), just incase this gives any insight into the problem: taxDetailsOverride, shippingtax1rate, total, taxtotal.
t
Can you share your script?
b
this sounds like a suitetax enabled account, in which case you want to be modifying the fields on the tax details subtab
x
This is the part that saves the rec:
Copy code
const setTransactionSummary = (transactionR... by Yoav Zinger
Yoav Zinger12:29

const setTransactionSummary = (transactionRecord, transaction, totalPrice) => {

            if (transaction.salesTax) {

                if (transaction.shippingFee) {

                    const taxRate = transaction.shippingFee.salesTaxRate.taxRate * 100;

                    transactionRecord.setValue({ fieldId: "shippingtax1rate", value: taxRate })

                }

                const salesTaxAmount = transaction.salesTax.amount;

                const total = salesTaxAmount + totalPrice;




                log.debug("before setValue total")

                transactionRecord.setValue({ fieldId: 'total', value: total });

                log.debug("after setValue total")




                log.debug("before setValue salesTaxAmount")

                transactionRecord.setValue({ fieldId: 'taxtotal', value: salesTaxAmount });

                log.debug("after setValue salesTaxAmount")




            }




            log.debug("before transactionRecord.save()")

            transactionRecord.save();

            log.debug("after transactionRecord.save()")

        }
we successfully replicated the "rounding error" in our sandbox environment! we are getting rounding error either the value of taxtotal is decimal 1-3 digits after the dot, or integer (like 7500) the error occurs when trying to save sales order that were created before our scripts were deployed. we still don't know what the differences are. we are using netsuite field explorer to check the differences.
t
have you try parsing the value here?
Copy code
salesTaxAmount + totalPrice;
like
Copy code
parseFloat(salesTaxAmount) + parseFloat(totalPrice);