AngularJS x-editable Locale-based decimal separator - javascript

I'm not able to make xeditable work with localized decimal numbers.
I have searched both in the official documentation and online in other forums/websites but I wasn't able to get any clue.
The only similar issue was this SO question: AngularJS xeditable number field with float validation
To sum up the problem: I would like to use a comma instead of a dot as a decimal separator but x-editable automatically transform the separator in a dot when I go into "edit mode". How can I deal with localization for decimal numbers?
Here is the code
<span e-form="rowform" e-name="value.value" editable-text="property.value.value" onbeforesave="checkIsNumeric($data)">
{property.value.value || 'empty'}}
</span>

Have you tried using a locale file like described in the angular i18n documentation? You should pick one of your language that already contains a comma. Otherwise theoretically you could manipulate your locale file and add a comma as decimal separator. The different locale files (angular 1.4.7) can be downloaded here for example.

Related

Can you use input type "number" for arbitrary precision decimals?

I would like to be able to handle numbers from e-18 (0.000000000000000001) to e4 (10,000) and do arithmetic on these inputs without rounding errors. So I cannot use the 64-bit double precision number native to JavaScript as it only has a safe range of 9e15 and I need a range of 1e22.
Can I use the HTML input type number for this in combination with the appropriate JavaScript, or should I use text instead?
Some code examples and npm libraries to help me solve this problem would be greatly appreciated.
1) The HTML input elements, always return a String represantation of the entered value.
2) For handling big numbers safely, you can either use the ES6 BigInt or if you want full cross-browser support, you can use a library such as big.js, bignumber.js or decimal.js, depending on your needs.
3) You might also want to take a look at the valueAsNumber property of the HTML input element (type=number). Beware of support issues for this one.
Bottom line: You will always get the value entered in the input field as a String data type via the value property, and you will have to parse it either natively or using a JS library as mention above.
Useful links about numbers and dealing with them in JavaScript:
Working with large integers in JavaScript
How numbers are encoded in JavaScript
When Your Code Does a Number on You: Navigating Numbers in JS (YouTube video)

How to use pattern mask for JSP input?

I'm using Spring MVC and dojo in my project.
We need to have an input for phone number by given format like: (###) ###-####
The phone number should automatically format as it's being typed.
The validation should be inside the text field it self with placeholder per each digit separated by '-'.
I tried to look over the web for an exist solution but I couldn't find any.
Can you try this library for phone number format?
https://www.npmjs.com/package/libphonenumber-js

How can I get the regional settings of the client to identify the client's decimal separator?

I want to parse a value using parseFloat() which I've read only recognises a decimal point(.) as a separator. I want to be able to run the page (without the user configuring anything) in the EU where they will naturally use the comma as a separator.
Is this possible? I've googled and it seems that this can't be done which I find odd.
Thanks
You can use replace() to replace , to . , after that you can parse as usual
var a="1,02";
console.log(parseFloat(a.replace(',','.')));

regular express for number formatting

I'm not an expert on regex and I need some help on formatting numbers.
This is what I have:
TheNumber = TheNumber.toString().split(/(?=(?:\d{3})+(?:\.|$))/g).join(",");
Basically, I want TheNumber to be formatted with commas to separate thousands and up to 3 decimal precision with a dot to indicate decimal if there are decimals. It should also work with negative numbers.
I'm not far only that for the moment
3234234.223512 becomes 3,234,234.223,512
Thanks for your help.
I found this Javascript library accounting.js
As mentioned in description.
Accounting.js is a tiny JavaScript library for number, money and currency formatting, with optional excel-style column rendering (to line up symbols and decimals). It's lightweight, fully localisable and has zero dependencies.
It does the same as your requirements and even a little more.
I'd solve the problem in two pieces rather than a single regular expression. In particular, I'd:
remove the decimal point and any following numbers from the string first
User your reg exp (minus the decimal part) to add commas to the first part
concatenate back the removed decimal point

JavaScript decimal value validation

I want to validate a decimal value in an ASP.NET web page using JavaScript, so that the user can enter numbers with only two decimals. The validation should also consider the current UI culture (e.g. ',' instead of '.'). I use Microsoft's Ajax Framework, is there any function included in the library for such a thing?
If values are separated by spacing you can simply use ^\s*(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)\s*$ regexp (and than use $1 and $2 matches as actual values)
And, more important thing is that all client-side data is insecure by default (because can be forged) so you anyway have to validate it on server.

Categories

Resources