Rounding to 2 decimal places...

Results 1 to 2 of 2

Thread: Rounding to 2 decimal places...

  1. #1
    PersonalFoul Guest

    Default Rounding to 2 decimal places...

    I have the following function that is successfully called, however I want to round to 2 decimal places. <BR><BR>function CalcGrossWages()<BR>{<BR>document.forms.frmPayPeri od.txtWagesEarned.value = document.forms.frmPayPeriod.txtHoursWorked.value * document.forms.frmPayPeriod.txtPayRate.value;<BR>} <BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default Generally you round to X...

    ...decimal places like so in JavaScript:<BR><BR>var X = 2;<BR>var nValue = 1234.5678;<BR>var nRoundedToXDecimals = Math.round(nValue * Math.pow(10, X)) / Math.pow(10, X);<BR><BR>This can obviously be optimized if X is the same all the time. You can get rid of the Math.pow(10, X) and put in the actual integer, i.e. 100 in the above example where X = 2.<BR><BR>Oliver.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts