[FIX] support 'thousands' separator for floats
lp bug: https://launchpad.net/bugs/886471 fixed bzr revid: xmo@openerp.com-20111114155332-3on98ot7o808z0gi
This commit is contained in:
parent
42c7cb86d9
commit
76a02ead76
|
@ -48,6 +48,19 @@ openerp.web.intersperse = function (str, indices, separator) {
|
|||
if (s) { result.push(s); }
|
||||
return result.reverse().join(separator);
|
||||
};
|
||||
/**
|
||||
* Insert "thousands" separators in the provided number (which is actually
|
||||
* a string)
|
||||
*
|
||||
* @param {String} num
|
||||
* @returns {String}
|
||||
*/
|
||||
openerp.web.insert_thousand_seps = function (num) {
|
||||
var negative = num[0] === '-';
|
||||
num = (negative ? num.slice(1) : num);
|
||||
return (negative ? '-' : '') + openerp.web.intersperse(
|
||||
num, _t.database.parameters.grouping, _t.database.parameters.thousands_sep);
|
||||
};
|
||||
/**
|
||||
* Formats a single atomic value based on a field descriptor
|
||||
*
|
||||
|
@ -72,12 +85,13 @@ openerp.web.format_value = function (value, descriptor, value_if_empty) {
|
|||
var l10n = _t.database.parameters;
|
||||
switch (descriptor.widget || descriptor.type) {
|
||||
case 'integer':
|
||||
return openerp.web.intersperse(
|
||||
_.sprintf('%d', value), l10n.grouping, l10n.thousands_sep);
|
||||
return openerp.web.insert_thousand_seps(
|
||||
_.sprintf('%d', value));
|
||||
case 'float':
|
||||
var precision = descriptor.digits ? descriptor.digits[1] : 2;
|
||||
return _.sprintf('%.' + precision + 'f', value)
|
||||
.replace('.', l10n.decimal_point);
|
||||
var formatted = _.sprintf('%.' + precision + 'f', value).split('.');
|
||||
formatted[0] = openerp.web.insert_thousand_seps(formatted[0]);
|
||||
return formatted.join(l10n.decimal_point);
|
||||
case 'float_time':
|
||||
return _.sprintf("%02d:%02d",
|
||||
Math.floor(value),
|
||||
|
|
|
@ -41,6 +41,12 @@ $(document).ready(function () {
|
|||
'1.00');
|
||||
equal(openerp.web.format_value(-11.25, {type: 'float'}),
|
||||
"-11.25");
|
||||
openerp.web._t.database.parameters.grouping = [1, 2, -1];
|
||||
equal(openerp.web.format_value(1111111.25, {type: 'float'}),
|
||||
"1111,11,1.25");
|
||||
openerp.web._t.database.parameters.grouping = [1, 0];
|
||||
equal(openerp.web.format_value(-11.25, {type: 'float'}),
|
||||
"-1,1.25");
|
||||
});
|
||||
// test("parse_datetime", function () {
|
||||
// var val = openerp.web.str_to_datetime("2009-05-04 12:34:23");
|
||||
|
|
Loading…
Reference in New Issue