mredkj.com logo

An update blog for mredkj.com

What's this blog about?

mredkj.com is an unfocused programmer resource from Matt, Eric, and Keith

This blog will keep you up to date with our latest site changes.

Wednesday, September 29, 2004

NumberFormat v1.5.3 - September 29, 2004

numberFormat.html
Between NumberFormat 1.5.1 and 1.5.2, I accidently took out the logic that checks for this.hasSeparators, so I fixed that bug. This meant setting setSeparators or setCommas to false didn't do anything.

posted by Keith [9/29/2004 02:17:00 AM] - permalink - 4 comments

4 comment(s):

Blogger Keith wrote:

daxin,

I tried your suggested changes, and couldn't get it to work as expected. For example, trying to truncate 1.57 to one place using nf.setPlaces(1, true) returned 1.6

Because I've gotten at least a couple inquiries about adding truncate functionality into NumberFormat, I started working on some of my own changes. The major change is in getRoundedNF, plus some other changes in setting this.truncate

Here's the getRoundedNF code

function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val); // v1.5.x - new
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);

return val;
}

The point of this is to take a number like 1.57 and make it 1.5 when truncating to one place. To opt for this, I'm going to add another argument to setPlacesNF, similar to daxin's suggestion.

Before putting my changes into a new NumberFormat version, I'm going to test some more, and ask for any other suggestions people might have. I'll consider making other changes, if they're minor.

Posted [1/28/2005 02:20:00 AM]  

Anonymous Anonymous wrote:

Hi,
I found that using big number in NumberFormat won't get expected result. For example :

99999999999999.99
will be formatted to
99,999,999,999,999.98

and so for this '9' number if more than 15 digit, even without decimal number, will be round up.

I thought these was javascript limitation in big number.
Do you have any sugestions to overcome this problem ?

TIA

Posted [6/29/2005 10:36:00 PM]  

Blogger Keith wrote:

I don't know when I'll be able to update the NumberFormat code. My idea to get around the javascript limitation would be to eliminate all numbers in the code, and work entirely with strings.

If anyone needs to add separators (such as commas), try using the addSeparatorsNF function in the nfbasic page. It's much less overhead than the NumberFormat script.

I tried 99999999999999.99 using addSeparatorsNF and it formatted as 99,999,999,999,999.99

Posted [7/02/2005 11:32:00 PM]  

Blogger Keith wrote:

NumberFormat 1.5.4 has been released. It adds truncate functionality. However, it does not address the long number JavaScript limitation.

Posted [8/24/2005 09:52:00 AM]  

Post a Comment