3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 describe("Ext.util.Format", function() {
16 var num = Ext.util.Format.number,
17 usMoney = Ext.util.Format.usMoney,
18 currency = Ext.util.Format.currency,
20 thousandSeparator: Ext.util.Format.thousandSeparator,
21 decimalSeparator: Ext.util.Format.decimalSeparator,
22 currencySign: Ext.util.Format.currencySign
25 describe("usMoney", function(){
26 it("should format with 2 decimals, prefixed by a dollar sign", function() {
27 expect(usMoney(1234.567)).toEqual("$1,234.57");
29 it("should format with 2 decimals, prefixed by a negative sign, and a dollar sign", function() {
30 expect(usMoney(-1234.567)).toEqual("-$1,234.57");
32 it("should format with a comma as a thousand separator", function() {
33 expect(usMoney(1234567.89)).toEqual("$1,234,567.89");
37 describe("currency in FR locale", function(){
38 beforeEach(function() {
39 Ext.apply(Ext.util.Format, {
40 thousandSeparator: '.',
41 decimalSeparator: ',',
42 currencySign: '\u20ac',
46 afterEach(function() {
47 Ext.apply(Ext.util.Format, savedFormatLocale);
50 it("should format with 2 decimals, prefixed by a euro sign", function() {
51 expect(currency(1234.567)).toEqual("\u20ac1.234,57");
53 it("should format with 2 decimals, prefixed by a negative sign, and a euro sign", function() {
54 expect(currency(-1234.567)).toEqual("-\u20ac1.234,57");
58 describe("number in default (US) locale", function() {
59 it("should format with no decimals", function() {
60 expect(num(1, "0")).toEqual("1");
62 it("should format with two decimals", function() {
63 expect(num(1, "0.00")).toEqual("1.00");
65 it("should format+round with two decimals, and no thousand separators", function() {
66 expect(num(1234.567, "0.00")).toEqual("1234.57");
68 it("should format+round with two decimals, and ',' as the thousand separator", function() {
69 expect(num(1234.567, ",0.00")).toEqual("1,234.57");
71 it("should format+round with no decimals, and ',' as the thousand separator", function() {
72 expect(num(1234.567, ",0")).toEqual("1,235");
76 describe("number using FR locale", function() {
77 var savedFormatLocale = {
78 thousandSeparator: Ext.util.Format.thousandSeparator,
79 decimalSeparator: Ext.util.Format.decimalSeparator,
80 currencySign: Ext.util.Format.currencySign,
81 dateFormat: Ext.util.Format.dateFormat
84 beforeEach(function() {
85 Ext.apply(Ext.util.Format, {
86 thousandSeparator: '.',
87 decimalSeparator: ',',
88 currencySign: '\u20ac',
92 afterEach(function() {
93 Ext.apply(Ext.util.Format, savedFormatLocale);
96 it("should format with no decimals", function() {
97 expect(num(1, "0")).toEqual("1");
99 it("should format with two decimals", function() {
100 expect(num(1, "0.00")).toEqual("1,00");
102 it("should format+round with two decimals, and no thousand separators", function() {
103 expect(num(1234.567, "0.00")).toEqual("1234,57");
105 it("should format+round with two decimals after a ',', and '.' as the thousand separator", function() {
106 expect(num(1234.567, ",0.00")).toEqual("1.234,57");
108 it("should format+round with no decimals, and '.' as the thousand separator", function() {
109 expect(num(1234.567, ",0")).toEqual("1.235");
113 // In Ext4, the "/i" suffix allows you to use locale-specific separators in the format string, as opposed
114 // to US/UK conventions. Output however ALWAYS follows the local settings in the Format singleton which may
115 // be overridden by locale files.
116 describe("number using FR locale with /i", function() {
117 var savedFormatLocale = {
118 thousandSeparator: Ext.util.Format.thousandSeparator,
119 decimalSeparator: Ext.util.Format.decimalSeparator,
120 currencySign: Ext.util.Format.currencySign,
121 dateFormat: Ext.util.Format.dateFormat
124 // set up the FR formatting locale
125 beforeEach(function() {
126 Ext.apply(Ext.util.Format, {
127 thousandSeparator: '.',
128 decimalSeparator: ',',
129 currencySign: '\u20ac',
133 afterEach(function() {
134 Ext.apply(Ext.util.Format, savedFormatLocale);
137 // Demonstrate "Incorrect" use with "/i". '.' means thousand separator and ',' means decimal in FR locale.
138 // Read carefully. In the formatting strings below, '.' is taken to mean thousand separator, and
139 // ',' is taken to mean decimal separator
140 it("should format with no decimals", function() {
141 expect(num(1, "0.00/i")).toEqual("1");
143 it("should format+round with no decimals, and '.' as thousand separator", function() {
144 expect(num(1234.567, "0.00/i")).toEqual("1.235");
146 it("should format+round with three decimals after a ',', and '.' as the thousand separator", function() {
147 expect(num(1234.567, ",0.00/i")).toEqual("1.234,567");
149 it("should format+round with one decimal, and no thousand separator", function() {
150 expect(num(1234.567, ",0/i")).toEqual("1234,6");
154 it("should format with two decimals", function() {
155 expect(num(1, "0,00/i")).toEqual("1,00");
157 it("should format+round with two decimals, and no thousand separators", function() {
158 expect(num(1234.567, "0,00/i")).toEqual("1234,57");
160 it("should format+round with two decimals after a ',', and '.' as the thousand separator", function() {
161 expect(num(1234.567, ".0,00/i")).toEqual("1.234,57");
163 it("should format+round with no decimals, and '.' as the thousand separator", function() {
164 expect(num(1234.567, ".0/i")).toEqual("1.235");
169 it("should check for a 0 value before appending negative", function(){
170 expect(num(-2.842170943040401e-14, "0,000.00")).toEqual('0.00');