Code Monkey home page Code Monkey logo

jquery-tocurrency's Introduction

jQuery-toCurrency

Easily convert numbers to formatted currencies with jQuery. If you've ever used Rails' number_to_currency you will find this familiar.

Usage

This plugin basically implements two methods:

  • $.toCurrency(number, [options]) - accepts a number (String or Number) and, optionally, some configuration options. Returns a string containing the number formatted as a currency.
  • $(selector).toCurrency([options]) - called on a jQuery selection, it interprets the element(s) text() as a number, and applies formatting to it.

Examples

	$.toCurrency(1000); // returns "€ 1,000.00"

or

	<span class="price">10000</span>
	<script>
		$(".price").toCurrency(); // $(".price").text() will now be "€ 10,000.00"
	</script>

Options

Both methods accept an object with configuration options as the last argument. The complete list with default values is the following:

	$(selector).toCurrency({
		precision: 2,           // decimal precision
		delimiter: ",",         // thousands delimiter
		separator: ".",         // decimal separator
		unit: "&euro;",         // unit
		format: "%u %n",        // format. %u is the placeholder for the unit, %n for the number
		negativeFormat: false   // format for negative numbers. If false, id defaults to the same format as positive numbers
	});

jquery-tocurrency's People

Contributors

lucaong avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.