0

Good day Everyone!

I want to know how to return the output with two decimal places. Instead of 10,000 I want it to return 10,000.00. Also I already put .toFixed(2) but it's not working.

When the amount has decimal number other than zero, the values appear on the printout, but when the decimal number has a zero value, the Zeros won't appear on the printout.

Also, I have added a value of Wtax that was pulled-out on a "Bill Credit" Transaction.

Output:

image showing data output

ManoDestra
  • 6,325
  • 6
  • 26
  • 50
Rodel
  • 29
  • 5
  • Possible duplicate of [How to format numbers using javascript?](http://stackoverflow.com/questions/5731193/how-to-format-numbers-using-javascript) – Jeremy J Starcher Jun 10 '16 at 12:33

3 Answers3

3

Numeral.js - is a library that you can use for number formatting. With that you can format your number as follows:

numeral(10000).format('$0,0.00');

Hope this will help you.

Oshadha
  • 546
  • 10
  • 25
2

You can try this

var x = 1000;       // Raw input 
x.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')  //returns you 1,000.00

Alternately you can use Netsuite's currency function too

nlapiFormatCurrency('1000');   // returns you 1,000.00
nlapiFormatCurrency('1000.98');   // returns you 1,000.98
Rockstar
  • 2,228
  • 3
  • 20
  • 39
  • Thank you sir, I'll try this/ – Rodel Jun 08 '16 at 09:21
  • when I put nlapiFormatCurrency in my code, the value ( 10000 ) does not show in the print out. – Rodel Jun 09 '16 at 05:24
  • You need to pass string value. – Rockstar Jun 09 '16 at 05:26
  • I'm a beginner in NetSuite development, could you please, give me idea on how to pass string value. Thank you. – Rodel Jun 09 '16 at 05:37
  • @Rodel if your input is not a string then just add `''` befoer the value you recieved. `eg : ''+your value` like ''+100 it will convert 100 into `string` '100' – Rockstar Jun 09 '16 at 06:19
  • you mean like this sir , nlapiFormatCurrency (' '+(parseFloat(search[x].getValue('debitamount'))+parseFloat(wtaxamt))) Thank you so much. – Rodel Jun 09 '16 at 06:39
  • But I guess `nlapiFormatCurrency` would work for number input also. If its not working give another try for string input. – Rockstar Jun 09 '16 at 13:34
  • like this : `nlapiFormatCurrency(''+(parseFloat(search[x].getValue('debitamount'))+parseFloa‌​t(wtaxamt)))` – Rockstar Jun 09 '16 at 13:35
0

You might consider below code. It can round off decimal values based on the decimal places.
This also addresses the issue when rounding off negative values by getting first the absolute value before rounding it off. Without doing that, you will have the following results which the 2nd sample is incorrect.
Results from typical approach

function roundDecimal(decimalNumber, decimalPlace)
{
//this is to make sure the rounding off is correct even if the decimal is equal to -0.995
var bIsNegative = false;
if (decimalNumber < 0)
{
    decimalNumber = Math.abs(decimalNumber);
    bIsNegative = true;
}
var fReturn = 0.00;
(decimalPlace == null || decimalPlace == '') ? 0 : decimalPlace;

var multiplierDivisor = Math.pow(10, decimalPlace);
fReturn = Math.round((parseFloat(decimalNumber) * multiplierDivisor).toFixed(decimalPlace)) / multiplierDivisor;

fReturn = (bIsNegative) ? (fReturn * -1) : fReturn;
fReturn = fReturn.toFixed(decimalPlace)

return fReturn;
}


Below are the test sample
Test sample1

And this test sample after addressing the issue for negative values.
enter image description here