google-code-export / jquery-formatcurrency

Automatically exported from code.google.com/p/jquery-formatcurrency
GNU General Public License v3.0
2 stars 0 forks source link

Create a setting to dropDecimal points. #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A user requested via email that we add a setting to remove decimal places.

From Daniel Scullin:
-----------------------------
Yeah, please do commit it. 

The context in which I'm using it is in the real estate business. Houses 
listed on the website need to be formatted as currency, but not down to 
the cents. My client asked if I could drop the .00

Since it is (displayed as) currency, I don't see an absolute need for a 
numberOfDecimalPlaces property since a currency displayed as $1,000.5 or 
even $1,000.53213 might be misinterpreted. I'd have to say the rounding 
logic is beyond the scope of your library and you should leave that 
portion to the business objects.

BUT (there is always a BUT)... If any math calculations will be done with 
your library, you need to allow for any number of decimal places. For 
instance, If I ordered 16.457 yards of lumber at $4.00 per yard.... the 
price technically would have 3 decimal places ($65.858) but again, this 
business logic may be beyond the scope of your project.

My .0002 cents. Thanks for you help and your nice jquery contribution!

-DJ
On Mon, Jun 22, 2009 at 9:20 PM, Ben Dewey <xxxx@hotmail.com> wrote:
Great are you okay with me commiting this?  Do you see any benefit to 
using a numberOfDecimalPlaces setting that could be set to 0?

-Ben

From: Daniel Scullin [mailto:xxx@gmail.com] 
Sent: Monday, June 22, 2009 3:28 PM
To: Ben Dewey
Subject: Re: FormatCurrency Decimals

I just did a

if (!settings.dropCents) {
  num = num + settings.decimalSymbol + cents;
}

And initialized it via $(".currency").formatCurrency( {dropCents: true} );

This seems to work while maintaining the default behavior. Thanks for your 
help Ben!

-DJ
On Mon, Jun 22, 2009 at 2:11 PM, Ben Dewey <xxxx@hotmail.com> wrote:
Daniel,

There isn’t currently a setting to disable that.

Although you can modify the code to support this.

Comment out the line that says. 

num = num + settings.decimalSymbol + cents;

by putting two // in front of it.

Please note, that this breaks the default behavior.  If you’re interested 
in supporting both the default behavior and the noCents setting, then let 
me know I’ll try to help you come up with something different.

-Ben Dewey

From: Daniel Scullin [mailto:xxxx@gmail.com] 
Sent: Monday, June 22, 2009 12:23 PM
To: xxxx@hotmail.com
Subject: FormatCurrency Decimals

Howdy Sir,

Using your jquery formatcurrency library, is there a way to drop the 
cents? For example...

1123.00 results $1,123

Any suggestions are appreciated. Thanks!

-DJ

Original issue reported on code.google.com by bdewe...@hotmail.com on 23 Jun 2009 at 3:06

GoogleCodeExporter commented 9 years ago
Committed

Original comment by bdewe...@hotmail.com on 23 Jun 2009 at 3:07