Coder Social home page Coder Social logo

numbro's Issues

defaultFormatCurrency

formatCurrency has no default setter.

I want formatCurrency() to default to 0,0[.]00 (with the currency symbol in the correct place)

1.5.0 breaks webpack builds

I think this has to do with issue #62, although in that issue it says that the relevant code was merged in 1.4.0 even though 1.4.0 doesn't break webpack so I'm not really sure.

Anyway, my theory is that because of some dynamic require webpack tries loading in all the files in the node_modules/numbro dir because that's how webpack handles dynamic requires.

The error is very long but it starts out like this:

WARNING in ./~/numbro/numbro.js
Critical dependencies:
970:60-112 the request of a dependency is an expression
 @ ./~/numbro/numbro.js 970:60-112

using languages in node

Hi there,

I think I am missing something :/

in node, load an additional language

var numbro = require('numbro');
numbro.language('en-ZA', require('../node_modules/numbro/dist/languages/en-ZA.min.js'));
numbro.language('en-ZA');

Would I need to do this for all the languages I would like available to the app?

Problem with currency symbols

Regarding issue #2 (number formatting in various "exotic" languages), we've got two additional problems:

Multiple currency symbols

In Japanese (and Chinese) prices can be formatted in two ways

  • ¥100 - international symbol, always as a prefix
  • 100円 - native symbol written, always as a suffix

in Chinese it's ¥ and 元 respectively
Used symbol mainly depends on context, but important thing is that both are commonly used.

Although we can choose place of currency symbol in format() function, we can't change it's style (choose symbol we prefer to use).

@BenjaminVanRyseghem had an idea we could introduce additional parameter to language configuration file called translatedSymbol. If this symbol is not defined, we fallback to currencySymbol.

Centesimal division

Several currencies in the world using separate symbol for centisimal division of the currency.
For example, in Poland main currency is called zloty and the international symbol of this currency is "zł".
1 zloty (1 zł) is divided into 100 grosz (100 gr), so prices are usually formatted in following way:
50.99 becomes 50zł 88gr.

Problem applies also to dollars & cents, punds & pennies, euro & cents and several other currencies so I think it would be nice to have such functionality.

One idea is to add additional parameter to currency symbol called "c" ("centisimal"):

numbro(50.99).format('0,0.00$'); // 50.99zł
numbro(50.99).format('0,0$ .00c'); // 50zł 99gr

I know it may looks little wierd, but on the other hand it lets user define formatting in more flexible way (to use space between currency and centisimal symbol or not).

What do you guys think about that?

multiply loses accuracy on minification

This is a problem that was noticed at my work for numeraljs
https://github.com/foretagsplatsen/numbro/blob/develop/numbro.js#L930-L937
where

...
var corrFactor = correctionFactor(accum, curr);
return (accum * corrFactor) * (curr * corrFactor) /
    (corrFactor * corrFactor);

the minifier will remove all those parenthesis and mess up the order of operation.
A more cumbersome but accurate solution:

var corrFactor = correctionFactor(accum, curr),
      result = accum * corrFactor;
      result *= curr * corrFactor;
      result /= corrFactor * corrFactor
return result;

or however you see fit, so long as the order is maintain after minifying.
Test against
numbro(46.6).multiply(0.575) === 26.795

Waiting for bower :)

Updated the old master via today to find it's moved. Waiting for bower to recognize it.

v1.5.0 error with browserify

I try to use numbro with browserify but this part of code is only compatible with nodejs

// Load all languages
        var fs = require('fs'),
            path = require('path');
        var langFiles = fs.readdirSync(path.join(__dirname, 'languages'));
        langFiles.forEach(function (langFile) {
            numbro.language(path.basename(langFile, '.js'), require(path.join(__dirname, 'languages', langFile)));
        });

Incorrectly reporting hasModule = true

Hi!

I am using numbro in the browser, like this:

var numbro = require('numbro');

But when compiling the source file I get this error on Chrome:

Uncaught TypeError: x.readdirSync is not a function

Basically the hasModule is returning true even when is not running in a NodeJS environment.

if (hasModule) {
        module.exports = numbro;

        // Load all languages
        var fs = require('fs'),
            path = require('path');
        var langFiles = fs.readdirSync(path.join(__dirname, 'languages'));
        langFiles.forEach(function (langFile) {
            numbro.language(path.basename(langFile, '.js'), require(path.join(__dirname, 'languages', langFile)));
        });
    }

Note:

I am using Browserify v10.2.4.
numbro 1.5.0

Thanks!

Multiply floating point errors

numeral(64.43).multiply(100); // 6443.000000000001

I know this is a floating point issue but I thought that is what this library was meant to sort out.

Use webstorm to replace numeral with numbro in gh-pages

Open the folder in webstorm. right click replace in path
Preserve case - checked, recursive checked.

find: numeraljs, replace: numbro
then
find: numeral, replace: numbro

That should take care of all the renaming and preserve casing so Numeral would be Numbro

Error with languages

Hebrews language part is giving me an error.

All languages have this code.

// Browser
    if (typeof window !== 'undefined' && window.numbro && window.numbro.language) {
        window.numbro.language(language.langLocaleCode, language);
    }

But Hebrews has:

// Browser
    if (typeof window !== 'undefined' && this.numbro && this.numbro.language) {
        this.numbro.language(language.langLocaleCode, language);
    }

It takes this.numbro instead of window.numbro?

Problem with Japanese abbreviations.

(moved from foretagsplatsen/Numeral-js/issues/9)

I've already reported this issue here adamwdraper/Numeral-js/issues/248, but as the original branch is not maintained anymore, I think it would be better to focus on your branch.

Now, Numeral.js is grouping numbers into 4 groups: thousands, milions, billions and trillions.

But, in case of Japanese (and I suppose it also applies to Chinese) numbers are grouped in slightly different way: every hundred, thousand and ten thousand.

100 -> 1百
1,000 -> 1千
10,000 -> 1万
100,000 -> 10万
1,000,000 -> 1百万
10,000,000 -> 1千万
100,000,000 -> 1億

Before I start fixing this issue, I'd like to discuss how to approach that problem.
Ideas:

  • add more abbreviations in library core
  • let languages define their own formatting/unformatting functions

Sample formatting function here: http://jsfiddle.net/tuknLbz8/1/

Anyway, I think we need more flexible architecture if we want to support even more complicated numeral systems like Indian numbering system.

Trailing "B" when formatting ordinal numbers

Hi,
I'm using your lib to format international ordinal numbers :

 numbro(myVar).format('ordinal')

Therefore, instead of getting "1st", I get a "1stB"
It's due to format format checker which use the d letter to check if a decimal formatting has been asked

I would recommand to set

bytes = ''

when you know the user has asked for an ordinal formatting (line 462 - 479)

Meanwhile, i'm using it that way

numbro(myVar).format('orinal')

Thanks

Improve the `Publishing` wiki page

I would like to add a section about:

  • updating the gh-page
  • updating the changelog file
  • updating the cdnjs
  • updating the npm package
  • increasing the version number is the source code here

But what @Graham42 did is an awesome starting point 😄

Rescueing lost history

First, thanks for forking and maintaining numeral-js! Nice to see the PRs from numeral finally getting merged!

However, I think your current fork has lost a lot of important history:

  • The git history is gone.
    • I can't see what changes were made compared to the original numeral-js (all that shows up is the rename and a bunch of version bumps when I look through the commits). I almost abandoned this fork entirely because it didn't look like it brought any improvements at all.
    • The git history also provides valuable documentation when browsing the source code and searching for bugs.
  • The changelog is gone.
    • Changelogs are useful when assessing a project to get a sense of how its API evolves, how the authors treat version changes, and more. It would be nice if we didn't lose it!
    • It's a great place to document all the fixes to numeral-js that have been made.

Also, since this project is a fork, continuing where development on numeral-js left off, I would propose numbering releases where numeral-js left off as well, so the first numbro release could be v0.6.0. That would fit nicely with the original changelog, and make the upgrade path from numeral-js easier to see.


I went ahead and rebased all of the numbro commits onto the end of your numeral-js fork, keeping the changelog and updating the version to v1.6.0. It's here (in the master-with-history branch).

Check out the full commit history

I can't pull-request it, because, since I rebased everything onto the numeral-js fork, there's no common history :)

So, my proposal is that you reset --hard my rebased fork, push --force it to the numbro repo here, push v1.6.0 to npm, and roll from there.

I'd love any feedback or other ideas for how we could keep the project's valuable history! :)

Release 1.3.1

Hi,

I was interested to get the last release of numbro (1.3.1) in order to fix a bug encountered with browserify.
Thus, I installed the last version from npm and unfortunately the bug was still present.
I checked the code of the package and it seems that the bug is still presents because the code hasn't been updated (latest pull request from Avetisk is missing)

Files on npm are different from the version currently deployed on git master branch.
(I tried to install the package directly from git and it works well)

Could you check that the version on npm is correct ?

Thx.

Redo the website

I would like to have a bootstrap like page with a navbar on top (one for formatting, one for currency, etc) and some categories in each page

What do you guys think?

Format decimal numbers

I stumble uppon your repo while skimming the many numeral.js issues. I'm trying to do some very basic formatting: 123456.123456 to 123'456.123456. Or in words:

  1. Format the part before the period
  2. Leave decimals untouched

numeral.js and numbro both seem to require you to know the number of decimals ahead or setting a big number (which will generate extra 0 at the end of the number).

Am I missing something? Thanks!

Why is 0 formatted as +0?

var string = numbro(-1).format('+0,0');
// '-1'

var string = numbro(1).format('+0,0');
// '+1'

var string = numbro(0).format('+0,0');
// '+0'

The last one I would expect just 0 without a + prefixed.

browserify attempts to load all language files

The patch in #66 automatically loads all language files for any commonjs scenario, browserify included.

While I can't really complain about doing this on the server with Node.js, doing this in the browser adds unnecessary bloat that I can't easily remove.

Possible solutions off the top of my head:

  • provide a way to specify an array of languages which defaults to all languages on Node
  • create special logic for Node within the commonjs scope

As a side effect, this might help with #70.

Inconsistent whitespace

I've noticed that indentation throughout the project mixes spaces and tabs which is really bad. The majority is 4-space indent so should we switch everything to that? I care less about what the indenation is and more that it should be consistent. It's important for having readable and meaningful diffs.

Once this is decided I'll make a pull request with the required changes and then add a grunt test to make sure new pull requests have whitespace consistent with the rest of the project.

Improve docs, explain [.]

I'm not sure what [.] does vs .

numbro.setDefaultCurrencyFormat('0,0.00');
vs
numbro.setDefaultCurrencyFormat('0,0[.]00');

Does [.] make the decimal optional? For example 8.00 would be $8 not $8.00. but 8.1 would be $8.10

Max significant numbers formating

Looking at the doc I can't find a way to fix the number of significant numbers. This is very useful when you are showing numbers in a fixed width container

For example if I want only 3 significant numbers:

  • 12345678=> 12.3m
  • 1234567=> 1.23m
  • 123456 => 123k
  • 12345 => 12.3k
  • 1234 => 1.23k
  • 123 => 123
  • 12.3 => 12.3
  • 1.23 => 1.23
  • 0.123 => 0.12
  • 0.0123 => 0.01

format string could be "3a" for this example

node 0.12 support

npm test and grunt build are currently failing under node v0.12. It would be nice if that runtime were supported.

the currency symbol is $ which is a currency symbol already by itself (the dollar..)

This gives us the problem that if we are in a euro country but we want to say the current number is in dollars we can't just format it like that

$ 00.00 will be come a euro number

Java for example has a special currency sign that is not by itself a currency symbol of any country. This way i can specify a format with a $ and that is then seen as that a plain literal that should just be in that place not replaced with anything.

So is there now a way to escape the $ sign so that it really just keeps that?

This is then also more of a question that we should have pure literal support so the format can be:

£ 00.00
$ 00.00
¥ 00.00

if we really want to show a certain or specifc currency and not just translate it automatically

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.