Git Product home page Git Product logo

numeral-js's Issues

Website dropdown typo

In the dropdown to select a language it says Portogues (Portugual), it should say Portugal without the second u

Editing input value resets to 0

Loving Numeral.js! But I noticed this issue. The initial format of an entered value works just fine. But if you go back in to edit the value, it will reset to 0. The only time it doesn't reset to 0 is when you add digits to the front of the number.

0 -> input 1000
// 1,000

1,000 -> edit 1,010
// 0

Fix? Important when dealing with large values, typing the whole value back in each time is counter-intuitive and opens the opportunity for user typos / error. It doesn't like copy-paste either, but I suspect it's one and the same issue.

Thanks!

Hide Zero

It would be nice if there is an option to not display zero values.

valueOf() support

Hello

I saw that you provide a value() method in order to retrieve the native value of the number.
Why not using the valueOf() method to do that, just like momentjs does? It'll make us able to use the object in comparisons such as obj > 1, and is better for semantic since it is a native method.

The implementation should be exactly like the value method:

    value : function () {
        return this._n;
    },

    valueOf : function () {
        return this._n;
    },

Append currency symbol.

In some languages the currency symbol is after the number (price). Are you planing this feature ?

Create a tag for version 1.3.1

Hi,
I'm trying to create a webjar (http://www.webjars.org/) for numeral-js
But for now I can only download the lib via https://github.com/adamwdraper/Numeral-js/zipball/master and it lead me to 2 pbs :
a/ it is the trunk of the lib, and can change without notice
b/ the zip created has the following first level folder : adamwdraper-Numeral-js-15de409
with a tag 1.3.1 it would be adamwdraper-Numeral-js-1.3.1 (handled automatically by github)
which is a lot more friendly (no need to know the hash of the master)

Thx,

Signed value

It would be nice if there could be option to always have signed value. In example:

numeral(-123.34).format('+0.0')  // -> -123.3
numeral(123.34).format('+0.0')   // -> +123.3

numeral(-123.34).format('+$0.0')  // -> -$123.3
numeral(123.34).format('+$0.0')   // -> +$123.3

Support for default currency formats in language files

The hypothetical scenario would be that you have an app that needs to be able to show a cost of something in various languages/currencies (which a ton of e-commerce sites do). It would be great if we could provide that to the developer rather than having them put a bunch of conditionals in their code so they can add the correct format.

It could then also be used in unformat for greater accuracy when working with the various language-specific currency formats — right now it's pretty inflexible.

Maybe similar to L, LL, LLL, and LLLL in Moment.js it would be something like:

$: $100k, € 500k, 500 tis. Kč, etc.
$$: $500,000, € 500.000, 500 000 Kč, etc.
$$$: $500,000.00, € 500.000,00, 500 000,00 Kč, etc.

Something like that — just quickly threw that together so it can obviously change. Feels like that's an area where Numeral-js could be really useful. Any thoughts? (I would be happy to write the code if there's interest.)

Inexact decimal subtraction

When a user subtracts a decimal from another decimal, the output can be inexact.

For example:

var firstNumber = numeral(123.1);
var secondNumber = numeral(123);

var result = firstNumber.subtract(secondNumber);

In this instance, result has the value of 0.09999999999999432 rather than 0.1.

prefix and suffix

is there any chance to be able to add prefix or suffix in the format?

something like
$ 0[.]00 */pcs

can become to
$ 5.42 /pcs

btw, very useful lib :)

Return a numeral on `numeral().unformat()`

Hi,

Would be great to be able to do something like this:

var value = numeral().unformat(value),
    discount = numeral().unformat(discount);

return value.subtract(discount);

Currently, the numeral.fn.unformat returns a Numeric instead of a instance of Numeral.

So I have to do that:

var value = numeral(numeral().unformat(value)),
    discount = numeral(numeral().unformat(discount));

return value.subtract(discount);

Makes sense?

Fallback on setting languages

Currently, Numeral.js opts for throwing an exception when setting to a language that is not defined. For some environments, this may be desirable, for others it is rather unfortunate.

I propose to offer fallbacks (possibly on a different call that language to avoid changing the interface):

  • if de-AT is requested, but not found, de is tried instead; this allows one file for Germany and Austria (and Luxembourg), which are close enough in this case.
  • if hm is requested and not found, fall back to C which is some default that poduces sensible-enough formatting, probably exactly what plain JavaScript would do or perhaps en

3.7504E7 unformat error

3.7504E7 Should be unformat to 37,504,000 rather than 3.7504 or other values
Is there any way to fix it quickly? Thanks

Support for Indian and other similar number formats

Was just talking to a friend about this and in parts of India (or maybe everywhere in India) they format numbers like so: 1,00,00,000 (separator after hundreds until the last thousand) which right now, I believe, is impossible to re-create. There are probably other languages too that format their numbers like this or even more differently.

This is probably a substantial change to how Numeral-js does things. To solve, I assume Numeral-js would need to allow functions instead of objects for the "separator" property of a language which would then allow people to write their own custom formatters. The other possibility is allowing them to specify a custom format like so: '00,00,00,00,00,00,000.00' or something, but that seems kind of unwieldy since you have to make it arbitrarily big to make sure it always works.

Parsing "1st" to 1

When you unformat "1st", it results in a trillion, because the 't' is recognised. While it should be 1.

Add support for locales

It shouldn't be that hard to implement. I took your numeral.js files and added some options.

numeral.delimiters = {
    thousands: ',',
    decimals: '.'
}

For french language, it should be something like that:

numeral.delimiters = {
    thousands: ' ',
    decimals: ','
}

Replace line 179 by

w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + numeral.delimiters.thousands);

Replace line 188 by

d = numeral.delimiters.decimals + toFixed(n._n, precision.length).split('.')[1]; 

This is a quick fix to add different kind of delimiters. If you're interested to make that lib a bit more complete. I suggest you to take a look at babel.numbers

http://babel.edgewall.org/wiki/ApiDocs/babel.numbers

Having something similar to that in javascript would be simply awesome.

1073741824 isn't converted to 1GB

numeral(1073741825).format('0b');
//"1GB"

numeral(1073741823).format('0b');
//"1024MB"

numeral(1073741824).format('0b');
//"1073741824"

Document rounding behavior

Currently the docs say nothing about rounding, requiring experimentation (or browsing the source) to see what's going on.

Bytes in other languages

I believe you should add bytes suffix (MB,KB,...) to the language definition.
For example in french, KB = Ko (because "byte" = "octet").
If you do this I can pull request the french modifications.

Max/Min length padding

Currently there isn't anyway to easily pad a number. For instance if I want my percentages to be at least 3 numbers, so that they are all roughly the same length, there isn't a way to do that easily. '0.0%' will result in xx.x% and x.x%.

Tagging 1.4.9 for Bower

Hey, can you for a git tag for 1.4.9? This helps when Bower users do

bower install numeral

Really appreciate your work! Thanks!

amd support

I get this error when trying to do numeral.unformat('R1,000,000');

Uncaught TypeError: Object function (input) {
        if (numeral.isNumeral(input)) {
            input = input.value();
        } else if (!Number(input)) {
            input = 0;
        }

        return new Numeral(Number(input));
    } has no method 'unformat' 

I'm using requirejs

Signed currency is inconsistent

Using a format specifier with '$' and '+' produces inconsistent behavior:

numeral(-1000).format('$+0,0') === '-$1,000'
numeral(1000).format('$+0,0') === '$+1,000'

Validating a number

It would be great if numeraljs would allow to validate a given string to be a number (or not).

I was wondering if this would be possible by using a similar approach like unformat(), removing thousand separator, the abbreviations first, then taking the result of

string.replace(/[^0-9.-]+/g, '')

and determining if the length is different to the length of the source string (--> check if the string contained invalid characters).

What do you think?

Expose languages collection

Hello,
numeral should expose the languages collection. This way the language definition is available.

In my case I'm removing the thousands delimiter and currency symbol from an input text and test if it's a number.

Example
var langData = numeral.languages()[numeral.language()];
var re = new RegExp('[' + langData.delimiters.thousands + langData.currency.symbol + ']', "g");
var rawValue = value.replace(re, '');
var isNumber = Number(rawValue);

Thanks

Numeral instantiated with non-numeric values return zero

This has probably not been changed as I'm expecting most are used to it defaulting to this behavior, but in my opinion, numeral('not a number') should definitely not evaluate to zero. Is there a particular reason that the top level parser sets something to a number right after ascertaining that it isn't numeric?

I'm not expecting the default behavior to change for this, but couldn't there be some sort of "tolerant" setting that can be optionally disabled?

added italian version

please find here the italian language for numeral.js

// numeral.js language configuration
// language : italian Italy (it)
// author : Giacomo Trombi : http://cinquepunti.it
(function () {
    var language = {
        delimiters: {
            thousands: '.',
            decimal: ','
        },
        abbreviations: {
            thousand: 'mila',
            million: 'mil'
        },
        ordinal: function (number) {
            var b = number % 10;
            return '°';
        },
        currency: {
            symbol: '€'
        }
    };

    // Node
    if (typeof module !== 'undefined' && module.exports) {
        module.exports = language;
    }
    // Browser
    if (typeof window !== 'undefined' && this.numeral && this.numeral.language) {
        this.numeral.language('it', language);
    }
}());

Language code should conform to some standard

At the moment, we have be-nl (where the country comes first) and en-gb (where the country comes second). This is confusing.

I propose adhering to some well-defined standard, cf. Wikipedia or what the HTTP Accept-Language header uses (BCP-47). The language comes first, the country is second and in uppercase. The languages from above would be nl-BE and en-GB.

Overriding units

I'd like to know how you might suggest implementing Numeral in an application which needs to display both bits and bytes, as well as requiring decimal and binary prefixed versions for each.

I'm happy to work towards a pull request with such functionality, but given the way the API is put together at present, I can't see any clean way to specify multiple behaviours, or even just parameters.

Return a new numeral on math operations

Hi,

Would be great to return a new numeral instance on math operations like this:

var value = numeral(100),
    discount = numeral(0);

return value.subtract(value.multiply(discount).divide(numeral(100)));

It will return 0 instead of 90 since the value.multiply(discount) will change the value instance to 0 instead of returning a new instance with 0.

The idea is to mutate the numeral instance only using numeral.fn.set instead of mutating the called instance.

WDYT?

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.