1 describe("Ext.util.Format", function() {
2 var num = Ext.util.Format.number,
3 usMoney = Ext.util.Format.usMoney,
4 currency = Ext.util.Format.currency,
6 thousandSeparator: Ext.util.Format.thousandSeparator,
7 decimalSeparator: Ext.util.Format.decimalSeparator,
8 currencySign: Ext.util.Format.currencySign
11 describe("usMoney", function(){
12 it("should format with 2 decimals, prefixed by a dollar sign", function() {
13 expect(usMoney(1234.567)).toEqual("$1,234.57");
15 it("should format with 2 decimals, prefixed by a negative sign, and a dollar sign", function() {
16 expect(usMoney(-1234.567)).toEqual("-$1,234.57");
18 it("should format with a comma as a thousand separator", function() {
19 expect(usMoney(1234567.89)).toEqual("$1,234,567.89");
23 describe("currency in FR locale", function(){
24 beforeEach(function() {
25 Ext.apply(Ext.util.Format, {
26 thousandSeparator: '.',
27 decimalSeparator: ',',
28 currencySign: '\u20ac',
32 afterEach(function() {
33 Ext.apply(Ext.util.Format, savedFormatLocale);
36 it("should format with 2 decimals, prefixed by a euro sign", function() {
37 expect(currency(1234.567)).toEqual("\u20ac1.234,57");
39 it("should format with 2 decimals, prefixed by a negative sign, and a euro sign", function() {
40 expect(currency(-1234.567)).toEqual("-\u20ac1.234,57");
44 describe("number in default (US) locale", function() {
45 it("should format with no decimals", function() {
46 expect(num(1, "0")).toEqual("1");
48 it("should format with two decimals", function() {
49 expect(num(1, "0.00")).toEqual("1.00");
51 it("should format+round with two decimals, and no thousand separators", function() {
52 expect(num(1234.567, "0.00")).toEqual("1234.57");
54 it("should format+round with two decimals, and ',' as the thousand separator", function() {
55 expect(num(1234.567, ",0.00")).toEqual("1,234.57");
57 it("should format+round with no decimals, and ',' as the thousand separator", function() {
58 expect(num(1234.567, ",0")).toEqual("1,235");
62 describe("number using FR locale", function() {
63 var savedFormatLocale = {
64 thousandSeparator: Ext.util.Format.thousandSeparator,
65 decimalSeparator: Ext.util.Format.decimalSeparator,
66 currencySign: Ext.util.Format.currencySign,
67 dateFormat: Ext.util.Format.dateFormat
70 beforeEach(function() {
71 Ext.apply(Ext.util.Format, {
72 thousandSeparator: '.',
73 decimalSeparator: ',',
74 currencySign: '\u20ac',
78 afterEach(function() {
79 Ext.apply(Ext.util.Format, savedFormatLocale);
82 it("should format with no decimals", function() {
83 expect(num(1, "0")).toEqual("1");
85 it("should format with two decimals", function() {
86 expect(num(1, "0.00")).toEqual("1,00");
88 it("should format+round with two decimals, and no thousand separators", function() {
89 expect(num(1234.567, "0.00")).toEqual("1234,57");
91 it("should format+round with two decimals after a ',', and '.' as the thousand separator", function() {
92 expect(num(1234.567, ",0.00")).toEqual("1.234,57");
94 it("should format+round with no decimals, and '.' as the thousand separator", function() {
95 expect(num(1234.567, ",0")).toEqual("1.235");
99 // In Ext4, the "/i" suffix allows you to use locale-specific separators in the format string, as opposed
100 // to US/UK conventions. Output however ALWAYS follows the local settings in the Format singleton which may
101 // be overridden by locale files.
102 describe("number using FR locale with /i", function() {
103 var savedFormatLocale = {
104 thousandSeparator: Ext.util.Format.thousandSeparator,
105 decimalSeparator: Ext.util.Format.decimalSeparator,
106 currencySign: Ext.util.Format.currencySign,
107 dateFormat: Ext.util.Format.dateFormat
110 // set up the FR formatting locale
111 beforeEach(function() {
112 Ext.apply(Ext.util.Format, {
113 thousandSeparator: '.',
114 decimalSeparator: ',',
115 currencySign: '\u20ac',
119 afterEach(function() {
120 Ext.apply(Ext.util.Format, savedFormatLocale);
123 // Demonstrate "Incorrect" use with "/i". '.' means thousand separator and ',' means decimal in FR locale.
124 // Read carefully. In the formatting strings below, '.' is taken to mean thousand separator, and
125 // ',' is taken to mean decimal separator
126 it("should format with no decimals", function() {
127 expect(num(1, "0.00/i")).toEqual("1");
129 it("should format+round with no decimals, and '.' as thousand separator", function() {
130 expect(num(1234.567, "0.00/i")).toEqual("1.235");
132 it("should format+round with three decimals after a ',', and '.' as the thousand separator", function() {
133 expect(num(1234.567, ",0.00/i")).toEqual("1.234,567");
135 it("should format+round with one decimal, and no thousand separator", function() {
136 expect(num(1234.567, ",0/i")).toEqual("1234,6");
140 it("should format with two decimals", function() {
141 expect(num(1, "0,00/i")).toEqual("1,00");
143 it("should format+round with two decimals, and no thousand separators", function() {
144 expect(num(1234.567, "0,00/i")).toEqual("1234,57");
146 it("should format+round with two decimals after a ',', and '.' as the thousand separator", function() {
147 expect(num(1234.567, ".0,00/i")).toEqual("1.234,57");
149 it("should format+round with no decimals, and '.' as the thousand separator", function() {
150 expect(num(1234.567, ".0/i")).toEqual("1.235");