javascript - Number().toLocaleString() has different format in different browsers -


i format float locale string (euro) , there different results in every browser. possible fix without own function?

var sum=2282.0000; var formated_sum = number(sum.tofixed(2)).tolocalestring("de-de", {style: "currency", currency: "eur"}); 

firefox result: 2.282,00 €

chrome result: 2.282 €

ie result: 2.282,00 €

safari result: 2282 €

safari results wrong, chrome results not bad. idea how fix without writing own function formatting?


this question may have answer here: inconsistent behavior of tolocalestring() in different browser no, question different because searching solution currency, not date

ecma 262 specifies function implementation dependent , takes no arguments.

produces string value represents number value formatted according conventions of host environment’s current locale. function implementation-dependent, , permissible, not encouraged, return same thing tostring.

note first parameter function used in future version of standard; recommended implementations not use parameter position else.

it in ecma internationalization api specification (which number.prototype.tolocalestring supersedes ecma 262 accepts 2 arguments)

this definition supersedes definition provided in es5, 15.7.4.3.

when tolocalestring method called optional arguments locales , options, following steps taken:

let x number value (as defined in es5, 15.7.4). if locales not provided, let locales undefined. if options not provided, let options undefined. let numberformat result of creating new object if expression new intl.numberformat(locales, options) intl.numberformat standard built-in constructor defined in 11.1.3. return result of calling formatnumber abstract operation (defined in 11.3.2) arguments numberformat , x. value of length property of tolocalestring method 0.

besides, mdn specifies safari has no support it.

as viable solution see this answer on so


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -