benjaminvanryseghem / numbro Goto Github PK
View Code? Open in Web Editor NEWA JS library for number formatting
Home Page: http://numbrojs.com
License: MIT License
A JS library for number formatting
Home Page: http://numbrojs.com
License: MIT License
Hi guys,
We definitely need a logo :)
Any idea?
The test file for Sweden seems to be a copy of the language definition, rather than a set of tests.
formatCurrency has no default setter.
I want formatCurrency() to default to 0,0[.]00
(with the currency symbol in the correct place)
this file should be removed
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
numbro(myval).toFixed(2) throws an error.
When I visit the numbro website at https://foretagsplatsen.github.io/numbro/, none of the links on top (except "numbro") work correctly.
For example, the "Getting Started"-link leads to "https://foretagsplatsen.github.io/getting-started.html" instead of "https://foretagsplatsen.github.io/numbro/getting-started.html".
I can reproduce this behaviour in all major browsers (IE11, FF37, Chrome42) on my Windows 7 x64 PC.
by example for french, the language file is named fr-FR
but the test file is named fr
, and set the language with the code fr
instead of fr-FR
.
I would be nice to clean this up 😄
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?
Path refers to old dist
path
The documentation page doesn't seem to be available yet.
Regarding issue #2 (number formatting in various "exotic" languages), we've got two additional problems:
In Japanese (and Chinese) prices can be formatted in two ways
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
.
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?
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
Updated the old master via today to find it's moved. Waiting for bower to recognize it.
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)));
});
like http://numbrojs.com/try-me.html#!lang=en-US&number=123456&format=000%20a
so one can share an example to another
The cdnjs link on the getting started page 404s
http://cdnjs.cloudflare.com/ajax/libs/numbro/1.5.0/min/numbro.min.js
Add some text to explain that the file min/languages.min.js
has to be included
Given a format string beginning with "+$", the output produced reads "$+". I would expect the output to read "+$".
PR to follow.
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!
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.
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
See also: adamwdraper/Numeral-js#123
Which references this implementation: https://gist.github.com/resident-uhlig/7906919
I don't love the syntax #N#
but at least it works!
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?
Guess who released without build the minified files 😢
All french versions have a wrong ordinal: it says "e" instead of "ème"
See here
(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:
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.
See here
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
See doc
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:
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.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! :)
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.
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?
Should probably be updated to "numbro"?
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:
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!
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.
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:
As a side effect, this might help with #70.
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.
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
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:
format string could be "3a" for this example
npm test
and grunt build
are currently failing under node v0.12. It would be nice if that runtime were supported.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.