leongersen / wnumb Goto Github PK
View Code? Open in Web Editor NEWwNumb - JavaScript Number & Money formatting
License: MIT License
wNumb - JavaScript Number & Money formatting
License: MIT License
Package contains unnecessary file - test.html
. I can do PR if your accept this issue.
Hello. I'm attempting to format a string for use with the tooltip, but I've noticed that whitespace will cause the text to go to multiple lines.
Please see the following fiddle: https://jsfiddle.net/jpk6r7ye/1/
If you uncomment the CSS, the text will go to a single line, but the box will not be formatted nicely. Any ideas for this?
@leongersen should there be an easier way to format large numbers?
Numeral.js uses a format
string -- the 0.00a
format on 1234567.89
will output 1.23m
. Producing the same output with wNumb would require a custom encoder / decoder.
Should / could this be built into wNumb? Maybe a format
option that accepts values "number (default)" or "large_number"?
Could install this via npm
?
Hi Leon, cool library! I just noticed that suffix
appears to not work, but postfix
does.
Here is my source from an implementation of your noUISlider.
var tooltipFormat = wNumb({
decimals: 0,
decoder: function(number){
return number * 1000;
},
encoder: function(number){
return number / 1000;
},
prefix: "$",
postfix: "k"
})
var salaryRangeSlider = $("#my-slider")[0];
noUiSlider.create(salaryRangeSlider, {
start: [10000, 225000],
connect: true,
tooltips: [tooltipFormat, tooltipFormat],
range: {
"min": [10000, 10000],
"64%": [100000, 25000],
"max": [250000]
}
});
Everything looks good in the tooltip, and it says $200k
. However, when the postfix
above is changed to suffix
the k
is never output into the tooltip.
Let me know if you would like more info!
Regards,
W
Your subdomain is being misused for the promotion of illegal gambling sites in Indonesia. url : depo25bonus25.refreshless.com
Here is my fiddle with problem.
https://jsfiddle.net/9nd5x348/6/
When I turn off wNumb formatting problem disappears
Hi there,
I'm currently using your nouislider which is registered on bower but I can't find the wnumb formatter extension on there.
Is there any chance you can register that one too?
Thanks :)
James
Uncaught TypeError: (intermediate value)(intermediate value)(...) is not a function
I'm using this library together with noUiSlider
and sometimes the steps are not correctly applied. I defined a step of 250
. That essentially works for most numbers, but sometimes is off by 1:
Even if I type 2.500
into the field, it is "corrected" and jumps back to 2.499
.
The next step works just fine though:
Like I said, this happens to some values, but not all. Here I should not be able to slide to that value but to 29.250
.
This is the current setup:
var rangeSlider = document.getElementById('slider-range');
var inputFormat = document.getElementById('input-format');
noUiSlider.create(rangeSlider, {
start: [250],
tooltips: [true],
step: 250,
range: {
'min': [250],
'max': [{{ $canInvestMax }}]
},
format: wNumb({
thousand: '.',
suffix: ' EUR'
})
});
rangeSlider.noUiSlider.on('update', function (values, handle) {
inputFormat.value = values[handle];
});
inputFormat.addEventListener('change', function () {
rangeSlider.noUiSlider.set(this.value);
});
When I remove this part, the error does not occur:
format: wNumb({
thousand: '.',
suffix: ' EUR'
})
And idea how to fix that? Both scripts are up-to-date. Testet with Safari and Chrome on macOS.
Is there an option to use 2 decimals but strip the decimals if they are double zeros .00
?
So something like 125.00
would output 125
but 125.50
would output 125.50
.
Edit
Sorry didn't notice the edit option, was trying to use the encoder option. Here is how I solved it if this helps anyone else.
const moneyFormat = wNumb({
prefix: '$',
thousand: ',',
decimals: 2,
edit: function(value) {
return value.replace(/\.00/g, '')
}
})
Hi,
I found your library to be extremely useful, except for one case that doesn't really have a solution without doing some hacky stuff that i hate. I need a way to allow strict matching of numbers (when other characters are present
var doubleFormat = wNumb({ mark: ',', thousand: '.', decimals: 2 }); console.log(doubleFormat.from('thisStillReturnsAValidNumber1.231,1231'));
I would like an option such that the previous code returns the text itself, not just the number from it, since it cannot be directly converted to a number.
I guess there is mistake in the code, in case of decimals set to 0.
// Reduce the number of decimals to the specified option.
if ( decimals ) {
input = toFixed( input, decimals );
}
And the fix:
// Reduce the number of decimals to the specified option.
if ( typeof decimals != 'undefined') {
input = toFixed( input, decimals );
}
Correct me, if i'm wrong. Thanks.
Data
I have the following value going into wNumb: 8.905
Format
Here is the wNum function setup:
moneyFormat: wNumb({ mark: ".", thousand: ",", decimals: 2, prefix: "$", postfix: "" }),
Expected Result
I am expecting $8.91 as the output value
Actual Result
I am getting $8.90 as the output value
To me this seems like an issue where it is not rounding correctly with 5 as the 3rd decimal digit I would expect it to round the 2nd digit to 1 instead of leave at 0 since I am specifying 2 Decimal places.
Interestingly, wNumb does a better job of rounding than C# does but it is always cases like this that do not round correctly #.#5 where # is a digit
Thoughts?
Hello
Please add bower.json
Because your package included in https://libraries.io/bower/wnumb
In the documentation you have the following example:
var Format = wNumb({
prefix: '$',
postfix: ',-',
thousand: ','
});
Format.to ( '90000' );
=> '$90,000,-'
Running it, instead of returning the desired result '$90,000,-'
, it returns false
.
Also, the case is not covered by your tests.
https://jsfiddle.net/1ho4LsjL/
I think your library deserves more attention, making it easy to navigate to this repo will help you get more stars!
When the option of decimals is equal to 0 the libary return a number with 4 decimals
wNumb decimal doesn't work :( , i set decimal options with 0/false , and he return for example: 2.9999999, 5.99999996 ....
Please, do it :)
var moneyWithDecimalMarks = wNumb({
thousand: ''',
});
1234567890123456: 1'234'567'890'123'456
12345678901234567: 12'345'678'901'234'568
123456789012345678: 123'456'789'012'345'680
1234567890123456789: 1'234'567'890'123'456'800
The first one is still correct but adding more numbers results in strange effects.
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.