openexchangerates / accounting.js

A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
http://openexchangerates.github.io/accounting.js
MIT License
4.95k stars 528 forks source link

Formatting the Negative number like MS Excel #61

Open shamanth-github opened 11 years ago

shamanth-github commented 11 years ago

Hi,

Very nice and light weight JS plugin for formatting the currencies!!

But however I am looking to extend this plugin to suit one of my requirement:

stephenroden commented 11 years ago

Try accounting.settings.currency.format = { pos : "%s%v", // for positive values, eg. "$1.00" (required) neg : "(%s%v)", // for negative values, eg. "($1.00)" [optional] zero: "%s%v" // for zero values, eg. "$0.00" [optional] };

jdross commented 11 years ago

Similar issue, but negative alignment should align ) differently than the final digit of positives.

Current behavior:

   $500.00
(-$500.00)

Expected behavior:

  $500.00
(-$500.00)
Lakshmi-Sharma commented 8 years ago

Alignment for column formatting with negative numbers would be great.

Although, (-$500.00) would defeat the purpose of representing -ve value with brackets. I hope you meant

  500.00
($500.00)
Lakshmi-Sharma commented 8 years ago

The above pull request fixes value alignment. Although, this can be further improved to check both positive number and negative number formatting.

For eg:

$  123.45 Cr
$ (123.45)

i.e. negative number is adjusted according to positive number.