parent
773c34900f
commit
49bf3f5b3a
|
@ -5,7 +5,7 @@ import {NumberWrapper, RegExpWrapper, Type, isBlank, isNumber, isPresent} from '
|
|||
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||
|
||||
var defaultLocale: string = 'en-US';
|
||||
const _NUMBER_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$'/g;
|
||||
const _NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$/g;
|
||||
|
||||
/**
|
||||
* Internal function to format numbers used by Decimal, Percent and Date pipes.
|
||||
|
@ -19,7 +19,7 @@ function formatNumber(
|
|||
}
|
||||
var minInt = 1, minFraction = 0, maxFraction = 3;
|
||||
if (isPresent(digits)) {
|
||||
var parts = RegExpWrapper.firstMatch(_NUMBER_REGEXP, digits);
|
||||
var parts = RegExpWrapper.firstMatch(_NUMBER_FORMAT_REGEXP, digits);
|
||||
if (isBlank(parts)) {
|
||||
throw new BaseException(`${digits} is not a valid digit info for number pipes`);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ export function main() {
|
|||
expect(pipe.transform(123, '.2')).toEqual('123.00');
|
||||
expect(pipe.transform(1, '3.')).toEqual('001');
|
||||
expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000');
|
||||
|
||||
expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
|
||||
expect(pipe.transform(1.1234)).toEqual('1.123');
|
||||
});
|
||||
|
@ -54,6 +53,7 @@ export function main() {
|
|||
it('should return correct value for numbers', () => {
|
||||
expect(pipe.transform(123)).toEqual('USD123');
|
||||
expect(pipe.transform(12, 'EUR', false, '.2')).toEqual('EUR12.00');
|
||||
expect(pipe.transform(5.123, 'USD', false, '.0-2')).toEqual('USD5.12');
|
||||
});
|
||||
|
||||
it('should not support other objects',
|
||||
|
|
Loading…
Reference in New Issue