Coder Social home page Coder Social logo

currencyformatter.js's People

Contributors

darkokukovec avatar jcbarton avatar magnusottosson avatar osrec avatar richardvenneman avatar swftvsn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

currencyformatter.js's Issues

Behaviour for '#' and '0'

The patterns do not behave as expected? When using #, the number should not substitute a 0 in the price, unless it is used with #0

This is correct:

OSREC.CurrencyFormatter.format(0.45, {pattern: "#,##0.## !"})

>> "0.45 $"

Incorrect (?):

OSREC.CurrencyFormatter.format(0.45, {pattern: "#,##.## !"})

>> "0.45 $"

Expected:

>> ".45 $"

Incorrect (?):

OSREC.CurrencyFormatter.format(120, {pattern: "#,##0.##00 !"})

>> "120.0000 $"

Expected:

>> "120.00 $"

Incorrect (?):

OSREC.CurrencyFormatter.format(120, {pattern: "#,##0.## !"})

>> "120.00 $"

Expected:

>> "120 $"

Is this not what was planned for the patterns?

Parsing force toFixed 2 decimals

For this case:

OSREC.CurrencyFormatter.parse('€ -99,50', { locale: 'it' });

The current behavior return:
-99.5
The expected behavior is:
Returns -99.50

Is there any way to do it?

Consider using unicode currency symbols

Hi,

Thanks for the great lib.

What's the reason HTML entities are being used for currency symbols? When rendering the CurrencyFormatter output in React/JSX this requires dangerouslySetInnerHTML, which is troublesome. Would you consider replacing the HTML entities with unicode characters? If so, I can make a pull request.

ReactJS support

Is there anyway to import this utlity in React? Like so:

import OSREC from 'currencyformatter.js';

Convert numbers into USD

So lets say my locale is it-it and I enter in the input 99,99 I want to convert that to 99.99 as the db expects to store this value in en-us

How to remove decimals?

Thanks for your great library. Easy and reliable.

I am trying to display

100 => $100 and not $100,00.

How to achieve it ?

Thanks.

Best Practice for Customizing formatAll ?

I hesitate to even call this an issue, since I'm just asking for advice. For our app, I expanded the matches[ i ] assignment in formatAll to make sure the existing string was a number (otherwise, I get errors) and to make sure it got applied to input elements (i.e., has value, not textContent)

` for (var i = 0; i < matches.length; ++i) {

        // handle, e.g., span, p, etc.
        if (!(isNaN(matches[i].textContent))) {
            var formattedString = formatter(matches[i].textContent);
            matches[i].textContent = formattedString;
        }

        // handle inputs
        if (!(isNaN(matches[i].value))) {
            var formattedString = formatter(matches[i].value);
            matches[i].value = formattedString;
        }
    }`

My two questions:

  1. Is there a better practice for avoiding the NaN problem.
  2. Is there a better practice for 'customizing' formatAll than hacking into currencyFormatter.js? I don't want to get caught off guard if I install an update.

Is it possible to extend this to cover crypto?

Hi,
i have a framework which covers Fiat and Crypto balances. Would it be possible to have a parameter which allowed you do edit the precision of the decimal? Some cryptos have 8 decimals and some 3, being able to show this and also remove the currency symbol would allow use across the board.

Customize

It will be cool if i could choose currencies what i need

Prevent number ticking from displaying on the dom

not exactly the best issue title, but im not quite sure what to call this. i would like to prevent the numbers from scrolling/tallying/iterating (whatever one calls this) on the dom like they are doing in this gif. given that this isnt an async func, how could i do this?

How use it on NPM?

import 'currencyformatter.js'

Uncaught ReferenceError: OSREC is not defined
at Object. (custom.js:148)
at fire (jquery.js:3268)
at Object.fireWith [as resolveWith] (jquery.js:3398)
at done (jquery.js:9305)
at XMLHttpRequest. (jquery.js:9548)

Can't disable symbol

Documentation states that I can pass custom symbol to the formatter, but it ignores an empty value.

I need to format only the number, without currency symbol. Currently it's impossible without extra code that strips non-numeric values from output.

Optionally remove symbol from formatting

Is it possible to format a currency without adding the symbol? I know it is possible with custom formatting but if I have to customise the formatting for all locales my use of this library becomes pointless.

I'm trying to format user input inside an input field. If the symbol trails the value the UX is weird. Here is an example of the problem: https://codepen.io/fuzzyvagina/pen/MXGYaj

It would be great if passing null as symbol disabled the symbol:

OSREC.CurrencyFormatter.format(123456, { currency: 'ISK', symbol: null }) 
// output: 123.456 rather than 123.456 kr

Rounding Off Issue

Is there a reason for the library to convert
OSREC.CurrencyFormatter.format(0.999, { currency: 'EUR'})

shows "1,00 €"

Is there a reason for this rounding off, and also is there a way to avoid this rounding off ?

Missing ES6 feature transpile

Hi, thanks for the library :)

I would like to know if you could transpile it to ES5. I'm getting an error because of this line:

return Math.abs(Number(str.replace(new RegExp(`[^0-9${decimal}]`, 'g'), '').replace(decimal, '.'))) * mult;

That happens when I run webpack -p so UglifyJS breaks

I've added some changes to be able to use ES6 in this PR #15 in the future. Thanks :)

symbol wrong direction

Hi all,
In Arab language we read from right to the left,
So for example if we want to read a price format in Saudi Arabian Riyal in arabic
it should be
screen shot 2018-05-10 at 8 54 15 pm
number in the left and symbol in the right

I know that we can solve it in format parameter but I think it would be better to concern this fix in future releases

And Thank you!

Wrong format MXN

Hi,

The format of the MXN is wrong, I fix this by changing:

es_MX: { h: 'es' },

To:

es_MX: { p: '!#,##0.00', g: ',', d: '.' },

In all js files.

I hope this can help.

Thank you,

Currencies and countries in JSON

Currencies and countries in JSON

Hi, what you think about pass currency and countries array to JSON. So the code goes be more legible, and javascript file will be smaller than now

Benefics

  • If someone want contribute with code a devoloper will worry just about code, not about arrays of currency and countries
  • JSON is faster, so performance not be affected by this change, maybe improved

NaN parsing CVE currency value

I have the formatted price in the currency CVE
formatted price is 3,000,00 This price is formatted from the android device based on the selected locale.

I'm using the below code to parse the currency

var currency = require("currencyformatter.js");
console.log(currency.parse('3,000,00 ',  { currency: 'CVE' } ));

The above code gives NaN.

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.