SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chris Fuel round function

    Can anyone alter this function so that it only rounds up to 2 decimal points and not down. So 2.7546666 would be 2.76 instead of 2.75 ??

    Thanks in advance

    Code:
    function currencyRound(value,seperator)
    {
    		if (!seperator)
    		{
    				// Default is dollar currency
    				seperator = '.';
    		}
    		var money_regex = /([0]*|[1-9]*)\.([0-9]{2})/;
    		var result = money_regex.exec(value);
    		if ( !result[1] && !result[2] )
    		{
    				// Woh nelly!
    				return false;
    		}
    		else if (!result[1] && result[2])
    		{
    				return (0 + seperator + result[2]);
    		}
    		else
    		{
    				return (result[1] + seperator + result[2]);
    		}
    }
    Last edited by Motivated; Aug 25, 2006 at 09:12.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why cant you just use:
    Code:
    var a = parseFloat("2.7546666").toFixed(2);
    Saul


Bookmarks

Posting Permissions

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