1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ******************************************************************************* 5 * Copyright (C) 1996-2007, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 */ 9 package com.ibm.icu.dev.demo.rbnf; 10 11 import java.util.Locale; 12 13 /** 14 * A collection of example rule sets for use with RuleBasedNumberFormat. 15 * These examples are intended to serve both as demonstrations of what can 16 * be done with this framework, and as starting points for designing new 17 * rule sets. 18 * 19 * For those that claim to represent number-spellout rules for languages 20 * other than U.S. English, we make no claims of either accuracy or 21 * completeness. In fact, we know them to be incomplete, and suspect 22 * most have mistakes in them. If you see something that you know is wrong, 23 * please tell us! 24 * 25 * @author Richard Gillam 26 */ 27 public class RbnfSampleRuleSets { 28 /** 29 * Puts a copyright in the .class file 30 */ 31 // private static final String copyrightNotice 32 // = "Copyright \u00a91997-1998 IBM Corp. All rights reserved."; 33 34 //======================================================================== 35 // Spellout rules for various languages 36 // 37 // The following RuleBasedNumberFormat descriptions show the rules for 38 // spelling out numeric values in various languages. As mentioned 39 // before, we cannot vouch for the accuracy or completeness of this 40 // data, although we believe it's pretty close. Basically, this 41 // represents one day's worth of Web-surfing. If you can supply the 42 // missing information in any of these rule sets, or if you find errors, 43 // or if you can supply spellout rules for languages that aren't shown 44 // here, we want to hear from you! 45 //======================================================================== 46 47 /** 48 * Spellout rules for U.S. English. This demonstration version of the 49 * U.S. English spellout rules has four variants: 1) %simplified is a 50 * set of rules showing the simple method of spelling out numbers in 51 * English: 289 is formatted as "two hundred eighty-nine". 2) %alt-teens 52 * is the same as %simplified, except that values between 1,000 and 9,999 53 * whose hundreds place isn't zero are formatted in hundreds. For example, 54 * 1,983 is formatted as "nineteen hundred eighty-three," and 2,183 is 55 * formatted as "twenty-one hundred eighty-three," but 2,083 is still 56 * formatted as "two thousand eighty-three." 3) %ordinal formats the 57 * values as ordinal numbers in English (e.g., 289 is "two hundred eighty- 58 * ninth"). 4) %default uses a more complicated algorithm to format 59 * numbers in a more natural way: 289 is formatted as "two hundred AND 60 * eighty-nine" and commas are inserted between the thousands groups for 61 * values above 100,000. 62 */ 63 public static final String usEnglish = 64 // This rule set shows the normal simple formatting rules for English 65 "%simplified:\n" 66 // negative number rule. This rule is used to format negative 67 // numbers. The result of formatting the number's absolute 68 // value is placed where the >> is. 69 + " -x: minus >>;\n" 70 // faction rule. This rule is used for formatting numbers 71 // with fractional parts. The result of formatting the 72 // number's integral part is substituted for the <<, and 73 // the result of formatting the number's fractional part 74 // (one digit at a time, e.g., 0.123 is "zero point one two 75 // three") replaces the >>. 76 + " x.x: << point >>;\n" 77 // the rules for the values from 0 to 19 are simply the 78 // words for those numbers 79 + " zero; one; two; three; four; five; six; seven; eight; nine;\n" 80 + " ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n" 81 + " seventeen; eighteen; nineteen;\n" 82 // beginning at 20, we use the >> to mark the position where 83 // the result of formatting the number's ones digit. Thus, 84 // we only need a new rule at every multiple of 10. Text in 85 // backets is omitted if the value being formatted is an 86 // even multiple of 10. 87 + " 20: twenty[->>];\n" 88 + " 30: thirty[->>];\n" 89 + " 40: forty[->>];\n" 90 + " 50: fifty[->>];\n" 91 + " 60: sixty[->>];\n" 92 + " 70: seventy[->>];\n" 93 + " 80: eighty[->>];\n" 94 + " 90: ninety[->>];\n" 95 // beginning at 100, we can use << to mark the position where 96 // the result of formatting the multiple of 100 is to be 97 // inserted. Notice also that the meaning of >> has shifted: 98 // here, it refers to both the ones place and the tens place. 99 // The meanings of the << and >> tokens depend on the base value 100 // of the rule. A rule's divisor is (usually) the highest 101 // power of 10 that is less than or equal to the rule's base 102 // value. The value being formatted is divided by the rule's 103 // divisor, and the integral quotient is used to get the text 104 // for <<, while the remainder is used to produce the text 105 // for >>. Again, text in brackets is omitted if the value 106 // being formatted is an even multiple of the rule's divisor 107 // (in this case, an even multiple of 100) 108 + " 100: << hundred[ >>];\n" 109 // The rules for the higher numbers work the same way as the 110 // rule for 100: Again, the << and >> tokens depend on the 111 // rule's divisor, which for all these rules is also the rule's 112 // base value. To group by thousand, we simply don't have any 113 // rules between 1,000 and 1,000,000. 114 + " 1000: << thousand[ >>];\n" 115 + " 1,000,000: << million[ >>];\n" 116 + " 1,000,000,000: << billion[ >>];\n" 117 + " 1,000,000,000,000: << trillion[ >>];\n" 118 // overflow rule. This rule specifies that values of a 119 // quadrillion or more are shown in numerals rather than words. 120 // The == token means to format (with new rules) the value 121 // being formatted by this rule and place the result where 122 // the == is. The #,##0 inside the == signs is a 123 // DecimalFormat pattern. It specifies that the value should 124 // be formatted with a DecimalFormat object, and that it 125 // should be formatted with no decimal places, at least one 126 // digit, and a thousands separator. 127 + " 1,000,000,000,000,000: =#,##0=;\n" 128 129 // This rule set formats numbers between 1,000 and 9,999 somewhat 130 // differently: If the hundreds digit is not zero, the first two 131 // digits are treated as a number of hundreds. For example, 2,197 132 // would come out as "twenty-one hundred ninety-seven." 133 + "%alt-teens:\n" 134 // just use %simplified to format values below 1,000 135 + " =%simplified=;\n" 136 // values between 1,000 and 9,999 are delegated to %%alt-hundreds 137 // for formatting. The > after "1000" decreases the exponent 138 // of the rule's radix by one, causing the rule's divisor 139 // to be 100 instead of 1,000. This causes the first TWO 140 // digits of the number, instead of just the first digit, 141 // to be sent to %%alt-hundreds 142 + " 1000>: <%%alt-hundreds<[ >>];\n" 143 // for values of 10,000 and more, we again just use %simplified 144 + " 10,000: =%simplified=;\n" 145 // This rule set uses some obscure voodoo of the description language 146 // to format the first two digits of a value in the thousands. 147 // The rule at 10 formats the first two digits as a multiple of 1,000 148 // and the rule at 11 formats the first two digits as a multiple of 149 // 100. This works because of something known as the "rollback rule": 150 // if the rule applicable to the value being formatted has two 151 // substitutions, the value being formatted is an even multiple of 152 // the rule's divisor, and the rule's base value ISN'T an even multiple 153 // if the rule's divisor, then the rule that precedes this one in the 154 // list is used instead. (The [] notation is implemented internally 155 // using this notation: a rule containing [] is split into two rules, 156 // and the right one is chosen using the rollback rule.) In this case, 157 // it means that if the first two digits are an even multiple of 10, 158 // they're formatted with the 10 rule (containing "thousand"), and if 159 // they're not, they're formatted with the 11 rule (containing 160 // "hundred"). %%empty is a hack to cause the rollback rule to be 161 // invoked: it makes the 11 rule have two substitutions, even though 162 // the second substitution (calling %%empty) doesn't actually do 163 // anything. 164 + "%%alt-hundreds:\n" 165 + " 0: SHOULD NEVER GET HERE!;\n" 166 + " 10: <%simplified< thousand;\n" 167 + " 11: =%simplified= hundred>%%empty>;\n" 168 + "%%empty:\n" 169 + " 0:;" 170 171 // this rule set is the same as %simplified, except that it formats 172 // the value as an ordinal number: 234 is formatted as "two hundred 173 // thirty-fourth". Notice the calls to ^simplified: we have to 174 // call %simplified to avoid getting "second hundred thirty-fourth." 175 + "%ordinal:\n" 176 + " zeroth; first; second; third; fourth; fifth; sixth; seventh;\n" 177 + " eighth; ninth;\n" 178 + " tenth; eleventh; twelfth; thirteenth; fourteenth;\n" 179 + " fifteenth; sixteenth; seventeenth; eighteenth;\n" 180 + " nineteenth;\n" 181 + " twentieth; twenty->>;\n" 182 + " 30: thirtieth; thirty->>;\n" 183 + " 40: fortieth; forty->>;\n" 184 + " 50: fiftieth; fifty->>;\n" 185 + " 60: sixtieth; sixty->>;\n" 186 + " 70: seventieth; seventy->>;\n" 187 + " 80: eightieth; eighty->>;\n" 188 + " 90: ninetieth; ninety->>;\n" 189 + " 100: <%simplified< hundredth; <%simplified< hundred >>;\n" 190 + " 1000: <%simplified< thousandth; <%simplified< thousand >>;\n" 191 + " 1,000,000: <%simplified< millionth; <%simplified< million >>;\n" 192 + " 1,000,000,000: <%simplified< billionth;\n" 193 + " <%simplified< billion >>;\n" 194 + " 1,000,000,000,000: <%simplified< trillionth;\n" 195 + " <%simplified< trillion >>;\n" 196 + " 1,000,000,000,000,000: =#,##0=;" 197 198 // %default is a more elaborate form of %simplified; It is basically 199 // the same, except that it introduces "and" before the ones digit 200 // when appropriate (basically, between the tens and ones digits) and 201 // separates the thousands groups with commas in values over 100,000. 202 + "%default:\n" 203 // negative-number and fraction rules. These are the same 204 // as those for %simplified, but ave to be stated here too 205 // because this is an entry point 206 + " -x: minus >>;\n" 207 + " x.x: << point >>;\n" 208 // just use %simplified for values below 100 209 + " =%simplified=;\n" 210 // for values from 100 to 9,999 use %%and to decide whether or 211 // not to interpose the "and" 212 + " 100: << hundred[ >%%and>];\n" 213 + " 1000: << thousand[ >%%and>];\n" 214 // for values of 100,000 and up, use %%commas to interpose the 215 // commas in the right places (and also to interpose the "and") 216 + " 100,000>>: << thousand[>%%commas>];\n" 217 + " 1,000,000: << million[>%%commas>];\n" 218 + " 1,000,000,000: << billion[>%%commas>];\n" 219 + " 1,000,000,000,000: << trillion[>%%commas>];\n" 220 + " 1,000,000,000,000,000: =#,##0=;\n" 221 // if the value passed to this rule set is greater than 100, don't 222 // add the "and"; if it's less than 100, add "and" before the last 223 // digits 224 + "%%and:\n" 225 + " and =%default=;\n" 226 + " 100: =%default=;\n" 227 // this rule set is used to place the commas 228 + "%%commas:\n" 229 // for values below 100, add "and" (the apostrophe at the 230 // beginning is ignored, but causes the space that follows it 231 // to be significant: this is necessary because the rules 232 // calling %%commas don't put a space before it) 233 + " ' and =%default=;\n" 234 // put a comma after the thousands (or whatever preceded the 235 // hundreds) 236 + " 100: , =%default=;\n" 237 // put a comma after the millions (or whatever precedes the 238 // thousands) 239 + " 1000: , <%default< thousand, >%default>;\n" 240 // and so on... 241 + " 1,000,000: , =%default=;" 242 // %%lenient-parse isn't really a set of number formatting rules; 243 // it's a set of collation rules. Lenient-parse mode uses a Collator 244 // object to compare fragments of the text being parsed to the text 245 // in the rules, allowing more leeway in the matching text. This set 246 // of rules tells the formatter to ignore commas when parsing (it 247 // already ignores spaces, which is why we refer to the space; it also 248 // ignores hyphens, making "twenty one" and "twenty-one" parse 249 // identically) 250 + "%%lenient-parse:\n" 251 + " & ' ' , ',' ;\n"; 252 253 /** 254 * Spellout rules for U.K. English. U.K. English has one significant 255 * difference from U.S. English: the names for values of 1,000,000,000 256 * and higher. In American English, each successive "-illion" is 1,000 257 * times greater than the preceding one: 1,000,000,000 is "one billion" 258 * and 1,000,000,000,000 is "one trillion." In British English, each 259 * successive "-illion" is one million times greater than the one before: 260 * "one billion" is 1,000,000,000,000 (or what Americans would call a 261 * "trillion"), and "one trillion" is 1,000,000,000,000,000,000. 262 * 1,000,000,000 in British English is "one thousand million." (This 263 * value is sometimes called a "milliard," but this word seems to have 264 * fallen into disuse.) 265 */ 266 public static final String ukEnglish = 267 "%simplified:\n" 268 + " -x: minus >>;\n" 269 + " x.x: << point >>;\n" 270 + " zero; one; two; three; four; five; six; seven; eight; nine;\n" 271 + " ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n" 272 + " seventeen; eighteen; nineteen;\n" 273 + " 20: twenty[->>];\n" 274 + " 30: thirty[->>];\n" 275 + " 40: forty[->>];\n" 276 + " 50: fifty[->>];\n" 277 + " 60: sixty[->>];\n" 278 + " 70: seventy[->>];\n" 279 + " 80: eighty[->>];\n" 280 + " 90: ninety[->>];\n" 281 + " 100: << hundred[ >>];\n" 282 + " 1000: << thousand[ >>];\n" 283 + " 1,000,000: << million[ >>];\n" 284 + " 1,000,000,000,000: << billion[ >>];\n" 285 + " 1,000,000,000,000,000: =#,##0=;\n" 286 + "%alt-teens:\n" 287 + " =%simplified=;\n" 288 + " 1000>: <%%alt-hundreds<[ >>];\n" 289 + " 10,000: =%simplified=;\n" 290 + " 1,000,000: << million[ >%simplified>];\n" 291 + " 1,000,000,000,000: << billion[ >%simplified>];\n" 292 + " 1,000,000,000,000,000: =#,##0=;\n" 293 + "%%alt-hundreds:\n" 294 + " 0: SHOULD NEVER GET HERE!;\n" 295 + " 10: <%simplified< thousand;\n" 296 + " 11: =%simplified= hundred>%%empty>;\n" 297 + "%%empty:\n" 298 + " 0:;" 299 + "%ordinal:\n" 300 + " zeroth; first; second; third; fourth; fifth; sixth; seventh;\n" 301 + " eighth; ninth;\n" 302 + " tenth; eleventh; twelfth; thirteenth; fourteenth;\n" 303 + " fifteenth; sixteenth; seventeenth; eighteenth;\n" 304 + " nineteenth;\n" 305 + " twentieth; twenty->>;\n" 306 + " 30: thirtieth; thirty->>;\n" 307 + " 40: fortieth; forty->>;\n" 308 + " 50: fiftieth; fifty->>;\n" 309 + " 60: sixtieth; sixty->>;\n" 310 + " 70: seventieth; seventy->>;\n" 311 + " 80: eightieth; eighty->>;\n" 312 + " 90: ninetieth; ninety->>;\n" 313 + " 100: <%simplified< hundredth; <%simplified< hundred >>;\n" 314 + " 1000: <%simplified< thousandth; <%simplified< thousand >>;\n" 315 + " 1,000,000: <%simplified< millionth; <%simplified< million >>;\n" 316 + " 1,000,000,000,000: <%simplified< billionth;\n" 317 + " <%simplified< billion >>;\n" 318 + " 1,000,000,000,000,000: =#,##0=;" 319 + "%default:\n" 320 + " -x: minus >>;\n" 321 + " x.x: << point >>;\n" 322 + " =%simplified=;\n" 323 + " 100: << hundred[ >%%and>];\n" 324 + " 1000: << thousand[ >%%and>];\n" 325 + " 100,000>>: << thousand[>%%commas>];\n" 326 + " 1,000,000: << million[>%%commas>];\n" 327 + " 1,000,000,000,000: << billion[>%%commas>];\n" 328 + " 1,000,000,000,000,000: =#,##0=;\n" 329 + "%%and:\n" 330 + " and =%default=;\n" 331 + " 100: =%default=;\n" 332 + "%%commas:\n" 333 + " ' and =%default=;\n" 334 + " 100: , =%default=;\n" 335 + " 1000: , <%default< thousand, >%default>;\n" 336 + " 1,000,000: , =%default=;" 337 + "%%lenient-parse:\n" 338 + " & ' ' , ',' ;\n"; 339 // Could someone please correct me if I'm wrong about "milliard" falling 340 // into disuse, or have missed any other details of how large numbers 341 // are rendered. Also, could someone please provide me with information 342 // on which other English-speaking countries use which system? Right now, 343 // I'm assuming that the U.S. system is used in Canada and that all the 344 // other English-speaking countries follow the British system. Can 345 // someone out there confirm this? 346 347 /** 348 * Spellout rules for Spanish. The Spanish rules are quite similar to 349 * the English rules, but there are some important differences: 350 * First, we have to provide separate rules for most of the twenties 351 * because the ones digit frequently picks up an accent mark that it 352 * doesn't have when standing alone. Second, each multiple of 100 has 353 * to be specified separately because the multiplier on 100 very often 354 * changes form in the contraction: 500 is "quinientos," not 355 * "cincocientos." In addition, the word for 100 is "cien" when 356 * standing alone, but changes to "ciento" when followed by more digits. 357 * There also some other differences. 358 */ 359 public static final String spanish = 360 // negative-number and fraction rules 361 "-x: menos >>;\n" 362 + "x.x: << punto >>;\n" 363 // words for values from 0 to 19 364 + "cero; uno; dos; tres; cuatro; cinco; seis; siete; ocho; nueve;\n" 365 + "diez; once; doce; trece; catorce; quince; diecis\u00e9is;\n" 366 + " diecisiete; dieciocho; diecinueve;\n" 367 // words for values from 20 to 29 (necessary because the ones digit 368 // often picks up an accent mark it doesn't have when standing alone) 369 + "veinte; veintiuno; veintid\u00f3s; veintitr\u00e9s; veinticuatro;\n" 370 + " veinticinco; veintis\u00e9is; veintisiete; veintiocho;\n" 371 + " veintinueve;\n" 372 // words for multiples of 10 (notice that the tens digit is separated 373 // from the ones digit by the word "y".) 374 + "30: treinta[ y >>];\n" 375 + "40: cuarenta[ y >>];\n" 376 + "50: cincuenta[ y >>];\n" 377 + "60: sesenta[ y >>];\n" 378 + "70: setenta[ y >>];\n" 379 + "80: ochenta[ y >>];\n" 380 + "90: noventa[ y >>];\n" 381 // 100 by itself is "cien," but 100 followed by something is "cineto" 382 + "100: cien;\n" 383 + "101: ciento >>;\n" 384 // words for multiples of 100 (must be stated because they're 385 // rarely simple concatenations) 386 + "200: doscientos[ >>];\n" 387 + "300: trescientos[ >>];\n" 388 + "400: cuatrocientos[ >>];\n" 389 + "500: quinientos[ >>];\n" 390 + "600: seiscientos[ >>];\n" 391 + "700: setecientos[ >>];\n" 392 + "800: ochocientos[ >>];\n" 393 + "900: novecientos[ >>];\n" 394 // for 1,000, the multiplier on "mil" is omitted: 2,000 is "dos mil," 395 // but 1,000 is just "mil." 396 + "1000: mil[ >>];\n" 397 + "2000: << mil[ >>];\n" 398 // 1,000,000 is "un millon," not "uno millon" 399 + "1,000,000: un mill\u00f3n[ >>];\n" 400 + "2,000,000: << mill\u00f3n[ >>];\n" 401 // overflow rule 402 + "1,000,000,000: =#,##0= (incomplete data);"; 403 // The Spanish rules are incomplete. I'm missing information on negative 404 // numbers and numbers with fractional parts. I also don't have 405 // information on numbers higher than the millions 406 407 /** 408 * Spellout rules for French. French adds some interesting quirks of its 409 * own: 1) The word "et" is interposed between the tens and ones digits, 410 * but only if the ones digit if 1: 20 is "vingt," and 2 is "vingt-deux," 411 * but 21 is "vingt-et-un." 2) There are no words for 70, 80, or 90. 412 * "quatre-vingts" ("four twenties") is used for 80, and values proceed 413 * by score from 60 to 99 (e.g., 73 is "soixante-treize" ["sixty-thirteen"]). 414 * Numbers from 1,100 to 1,199 are rendered as hundreds rather than 415 * thousands: 1,100 is "onze cents" ("eleven hundred"), rather than 416 * "mille cent" ("one thousand one hundred") 417 */ 418 public static final String french = 419 // the main rule set 420 "%main:\n" 421 // negative-number and fraction rules 422 + " -x: moins >>;\n" 423 + " x.x: << virgule >>;\n" 424 // words for numbers from 0 to 10 425 + " z\u00e9ro; un; deux; trois; quatre; cinq; six; sept; huit; neuf;\n" 426 + " dix; onze; douze; treize; quatorze; quinze; seize;\n" 427 + " dix-sept; dix-huit; dix-neuf;\n" 428 // ords for the multiples of 10: %%alt-ones inserts "et" 429 // when needed 430 + " 20: vingt[->%%alt-ones>];\n" 431 + " 30: trente[->%%alt-ones>];\n" 432 + " 40: quarante[->%%alt-ones>];\n" 433 + " 50: cinquante[->%%alt-ones>];\n" 434 // rule for 60. The /20 causes this rule's multiplier to be 435 // 20 rather than 10, allowinhg us to recurse for all values 436 // from 60 to 79... 437 + " 60/20: soixante[->%%alt-ones>];\n" 438 // ...except for 71, which must be special-cased 439 + " 71: soixante et onze;\n" 440 // at 72, we have to repeat the rule for 60 to get us to 79 441 + " 72/20: soixante->%%alt-ones>;\n" 442 // at 80, we state a new rule with the phrase for 80. Since 443 // it changes form when there's a ones digit, we need a second 444 // rule at 81. This rule also includes "/20," allowing it to 445 // be used correctly for all values up to 99 446 + " 80: quatre-vingts; 81/20: quatre-vingt->>;\n" 447 // "cent" becomes plural when preceded by a multiplier, and 448 // the multiplier is omitted from the singular form 449 + " 100: cent[ >>];\n" 450 + " 200: << cents[ >>];\n" 451 + " 1000: mille[ >>];\n" 452 // values from 1,100 to 1,199 are rendered as "onze cents..." 453 // instead of "mille cent..." The > after "1000" decreases 454 // the rule's exponent, causing its multiplier to be 100 instead 455 // of 1,000. This prevents us from getting "onze cents cent 456 // vingt-deux" ("eleven hundred one hundred twenty-two"). 457 + " 1100>: onze cents[ >>];\n" 458 // at 1,200, we go back to formating in thousands, so we 459 // repeat the rule for 1,000 460 + " 1200: mille >>;\n" 461 // at 2,000, the multiplier is added 462 + " 2000: << mille[ >>];\n" 463 + " 1,000,000: << million[ >>];\n" 464 + " 1,000,000,000: << milliarde[ >>];\n" 465 + " 1,000,000,000,000: << billion[ >>];\n" 466 + " 1,000,000,000,000,000: =#,##0=;\n" 467 // %%alt-ones is used to insert "et" when the ones digit is 1 468 + "%%alt-ones:\n" 469 + " ; et-un; =%main=;"; 470 471 /** 472 * Spellout rules for Swiss French. Swiss French differs from French French 473 * in that it does have words for 70, 80, and 90. This rule set shows them, 474 * and is simpler as a result. 475 */ 476 public static final String swissFrench = 477 "%main:\n" 478 + " -x: moins >>;\n" 479 + " x.x: << virgule >>;\n" 480 + " z\u00e9ro; un; deux; trois; quatre; cinq; six; sept; huit; neuf;\n" 481 + " dix; onze; douze; treize; quatorze; quinze; seize;\n" 482 + " dix-sept; dix-huit; dix-neuf;\n" 483 + " 20: vingt[->%%alt-ones>];\n" 484 + " 30: trente[->%%alt-ones>];\n" 485 + " 40: quarante[->%%alt-ones>];\n" 486 + " 50: cinquante[->%%alt-ones>];\n" 487 + " 60: soixante[->%%alt-ones>];\n" 488 // notice new words for 70, 80, and 90 489 + " 70: septante[->%%alt-ones>];\n" 490 + " 80: octante[->%%alt-ones>];\n" 491 + " 90: nonante[->%%alt-ones>];\n" 492 + " 100: cent[ >>];\n" 493 + " 200: << cents[ >>];\n" 494 + " 1000: mille[ >>];\n" 495 + " 1100>: onze cents[ >>];\n" 496 + " 1200: mille >>;\n" 497 + " 2000: << mille[ >>];\n" 498 + " 1,000,000: << million[ >>];\n" 499 + " 1,000,000,000: << milliarde[ >>];\n" 500 + " 1,000,000,000,000: << billion[ >>];\n" 501 + " 1,000,000,000,000,000: =#,##0=;\n" 502 + "%%alt-ones:\n" 503 + " ; et-un; =%main=;"; 504 // I'm not 100% sure about Swiss French. Is 505 // this correct? Is "onze cents" commonly used for 1,100 in both France 506 // and Switzerland? Can someone fill me in on the rules for the other 507 // French-speaking countries? I've heard conflicting opinions on which 508 // version is used in Canada, and I understand there's an alternate set 509 // of words for 70, 80, and 90 that is used somewhere, but I don't know 510 // what those words are or where they're used. 511 512 /** 513 * Spellout rules for German. German also adds some interesting 514 * characteristics. For values below 1,000,000, numbers are customarily 515 * written out as a single word. And the ones digit PRECEDES the tens 516 * digit (e.g., 23 is "dreiundzwanzig," not "zwanzigunddrei"). 517 */ 518 public static final String german = 519 // 1 is "eins" when by itself, but turns into "ein" in most 520 // combinations 521 "%alt-ones:\n" 522 + " null; eins; =%%main=;\n" 523 + "%%main:\n" 524 // words for numbers from 0 to 12. Notice that the values 525 // from 13 to 19 can derived algorithmically, unlike in most 526 // other languages 527 + " null; ein; zwei; drei; vier; f\u00fcnf; sechs; sieben; acht; neun;\n" 528 + " zehn; elf; zw\u00f6lf; >>zehn;\n" 529 // rules for the multiples of 10. Notice that the ones digit 530 // goes on the front 531 + " 20: [>>und]zwanzig;\n" 532 + " 30: [>>und]drei\u00dfig;\n" 533 + " 40: [>>und]vierzig;\n" 534 + " 50: [>>und]f\u00fcnfzig;\n" 535 + " 60: [>>und]sechzig;\n" 536 + " 70: [>>und]siebzig;\n" 537 + " 80: [>>und]achtzig;\n" 538 + " 90: [>>und]neunzig;\n" 539 + " 100: hundert[>%alt-ones>];\n" 540 + " 200: <<hundert[>%alt-ones>];\n" 541 + " 1000: tausend[>%alt-ones>];\n" 542 + " 2000: <<tausend[>%alt-ones>];\n" 543 + " 1,000,000: eine Million[ >%alt-ones>];\n" 544 + " 2,000,000: << Millionen[ >%alt-ones>];\n" 545 + " 1,000,000,000: eine Milliarde[ >%alt-ones>];\n" 546 + " 2,000,000,000: << Milliarden[ >%alt-ones>];\n" 547 + " 1,000,000,000,000: eine Billion[ >%alt-ones>];\n" 548 + " 2,000,000,000,000: << Billionen[ >%alt-ones>];\n" 549 + " 1,000,000,000,000,000: =#,##0=;"; 550 // again, I'm not 100% sure of these rules. I think both "hundert" and 551 // "einhundert" are correct or 100, but I'm not sure which is preferable 552 // in situations where this framework is likely to be used. Also, is it 553 // really true that numbers are run together into compound words all the 554 // time? And again, I'm missing information on negative numbers and 555 // decimals. 556 557 /** 558 * Spellout rules for Italian. Like German, most Italian numbers are 559 * written as single words. What makes these rules complicated is the rule 560 * that says that when a word ending in a vowel and a word beginning with 561 * a vowel are combined into a compound, the vowel is dropped from the 562 * end of the first word: 180 is "centottanta," not "centoottanta." 563 * The complexity of this rule set is to produce this behavior. 564 */ 565 public static final String italian = 566 // main rule set. Follows the patterns of the preceding rule sets, 567 // except that the final vowel is omitted from words ending in 568 // vowels when they are followed by another word; instead, we have 569 // separate rule sets that are identical to this one, except that 570 // all the words that don't begin with a vowel have a vowel tacked 571 // onto them at the front. A word ending in a vowel calls a 572 // substitution that will supply that vowel, unless that vowel is to 573 // be elided. 574 "%main:\n" 575 + " -x: meno >>;\n" 576 + " x.x: << virgola >>;\n" 577 + " zero; uno; due; tre; quattro; cinque; sei; sette; otto;\n" 578 + " nove;\n" 579 + " dieci; undici; dodici; tredici; quattordici; quindici; sedici;\n" 580 + " diciasette; diciotto; diciannove;\n" 581 + " 20: venti; vent>%%with-i>;\n" 582 + " 30: trenta; trent>%%with-i>;\n" 583 + " 40: quaranta; quarant>%%with-a>;\n" 584 + " 50: cinquanta; cinquant>%%with-a>;\n" 585 + " 60: sessanta; sessant>%%with-a>;\n" 586 + " 70: settanta; settant>%%with-a>;\n" 587 + " 80: ottanta; ottant>%%with-a>;\n" 588 + " 90: novanta; novant>%%with-a>;\n" 589 + " 100: cento; cent[>%%with-o>];\n" 590 + " 200: <<cento; <<cent[>%%with-o>];\n" 591 + " 1000: mille; mill[>%%with-i>];\n" 592 + " 2000: <<mila; <<mil[>%%with-a>];\n" 593 + " 100,000>>: <<mila[ >>];\n" 594 + " 1,000,000: =#,##0= (incomplete data);\n" 595 + "%%with-a:\n" 596 + " azero; uno; adue; atre; aquattro; acinque; asei; asette; otto;\n" 597 + " anove;\n" 598 + " adieci; undici; adodici; atredici; aquattordici; aquindici; asedici;\n" 599 + " adiciasette; adiciotto; adiciannove;\n" 600 + " 20: aventi; avent>%%with-i>;\n" 601 + " 30: atrenta; atrent>%%with-i>;\n" 602 + " 40: aquaranta; aquarant>%%with-a>;\n" 603 + " 50: acinquanta; acinquant>%%with-a>;\n" 604 + " 60: asessanta; asessant>%%with-a>;\n" 605 + " 70: asettanta; asettant>%%with-a>;\n" 606 + " 80: ottanta; ottant>%%with-a>;\n" 607 + " 90: anovanta; anovant>%%with-a>;\n" 608 + " 100: acento; acent[>%%with-o>];\n" 609 + " 200: <%%with-a<cento; <%%with-a<cent[>%%with-o>];\n" 610 + " 1000: amille; amill[>%%with-i>];\n" 611 + " 2000: <%%with-a<mila; <%%with-a<mil[>%%with-a>];\n" 612 + " 100,000: =%main=;\n" 613 + "%%with-i:\n" 614 + " izero; uno; idue; itre; iquattro; icinque; isei; isette; otto;\n" 615 + " inove;\n" 616 + " idieci; undici; idodici; itredici; iquattordici; iquindici; isedici;\n" 617 + " idiciasette; idiciotto; idiciannove;\n" 618 + " 20: iventi; ivent>%%with-i>;\n" 619 + " 30: itrenta; itrent>%%with-i>;\n" 620 + " 40: iquaranta; iquarant>%%with-a>;\n" 621 + " 50: icinquanta; icinquant>%%with-a>;\n" 622 + " 60: isessanta; isessant>%%with-a>;\n" 623 + " 70: isettanta; isettant>%%with-a>;\n" 624 + " 80: ottanta; ottant>%%with-a>;\n" 625 + " 90: inovanta; inovant>%%with-a>;\n" 626 + " 100: icento; icent[>%%with-o>];\n" 627 + " 200: <%%with-i<cento; <%%with-i<cent[>%%with-o>];\n" 628 + " 1000: imille; imill[>%%with-i>];\n" 629 + " 2000: <%%with-i<mila; <%%with-i<mil[>%%with-a>];\n" 630 + " 100,000: =%main=;\n" 631 + "%%with-o:\n" 632 + " ozero; uno; odue; otre; oquattro; ocinque; osei; osette; otto;\n" 633 + " onove;\n" 634 + " odieci; undici; ododici; otredici; oquattordici; oquindici; osedici;\n" 635 + " odiciasette; odiciotto; odiciannove;\n" 636 + " 20: oventi; ovent>%%with-i>;\n" 637 + " 30: otrenta; otrent>%%with-i>;\n" 638 + " 40: oquaranta; oquarant>%%with-a>;\n" 639 + " 50: ocinquanta; ocinquant>%%with-a>;\n" 640 + " 60: osessanta; osessant>%%with-a>;\n" 641 + " 70: osettanta; osettant>%%with-a>;\n" 642 + " 80: ottanta; ottant>%%with-a>;\n" 643 + " 90: onovanta; onovant>%%with-a>;\n" 644 + " 100: ocento; ocent[>%%with-o>];\n" 645 + " 200: <%%with-o<cento; <%%with-o<cent[>%%with-o>];\n" 646 + " 1000: omille; omill[>%%with-i>];\n" 647 + " 2000: <%%with-o<mila; <%%with-o<mil[>%%with-a>];\n" 648 + " 100,000: =%main=;\n"; 649 // Can someone confirm that I did the vowel-eliding thing right? I'm 650 // not 100% sure I'm doing it in all the right places, or completely 651 // correctly. Also, I don't have information for negatives and decimals, 652 // and I lack words fror values from 1,000,000 on up. 653 654 /** 655 * Spellout rules for Swedish. 656 */ 657 public static final String swedish = 658 "noll; ett; tv\u00e5; tre; fyra; fem; sex; sjo; \u00e5tta; nio;\n" 659 + "tio; elva; tolv; tretton; fjorton; femton; sexton; sjutton; arton; nitton;\n" 660 + "20: tjugo[>>];\n" 661 + "30: trettio[>>];\n" 662 + "40: fyrtio[>>];\n" 663 + "50: femtio[>>];\n" 664 + "60: sextio[>>];\n" 665 + "70: sjuttio[>>];\n" 666 + "80: \u00e5ttio[>>];\n" 667 + "90: nittio[>>];\n" 668 + "100: hundra[>>];\n" 669 + "200: <<hundra[>>];\n" 670 + "1000: tusen[ >>];\n" 671 + "2000: << tusen[ >>];\n" 672 + "1,000,000: en miljon[ >>];\n" 673 + "2,000,000: << miljon[ >>];\n" 674 + "1,000,000,000: en miljard[ >>];\n" 675 + "2,000,000,000: << miljard[ >>];\n" 676 + "1,000,000,000,000: en biljon[ >>];\n" 677 + "2,000,000,000,000: << biljon[ >>];\n" 678 + "1,000,000,000,000,000: =#,##0="; 679 // can someone supply me with information on negatives and decimals? 680 681 /** 682 * Spellout rules for Dutch. Notice that in Dutch, as in German, 683 * the ones digit precedes the tens digit. 684 */ 685 public static final String dutch = 686 " -x: min >>;\n" 687 + "x.x: << komma >>;\n" 688 + "(zero?); een; twee; drie; vier; vijf; zes; zeven; acht; negen;\n" 689 + "tien; elf; twaalf; dertien; veertien; vijftien; zestien;\n" 690 + "zeventien; achtien; negentien;\n" 691 + "20: [>> en ]twintig;\n" 692 + "30: [>> en ]dertig;\n" 693 + "40: [>> en ]veertig;\n" 694 + "50: [>> en ]vijftig;\n" 695 + "60: [>> en ]zestig;\n" 696 + "70: [>> en ]zeventig;\n" 697 + "80: [>> en ]tachtig;\n" 698 + "90: [>> en ]negentig;\n" 699 + "100: << honderd[ >>];\n" 700 + "1000: << duizend[ >>];\n" 701 + "1,000,000: << miljoen[ >>];\n" 702 + "1,000,000,000: << biljoen[ >>];\n" 703 + "1,000,000,000,000: =#,##0="; 704 705 /** 706 * Spellout rules for Japanese. In Japanese, there really isn't any 707 * distinction between a number written out in digits and a number 708 * written out in words: the ideographic characters are both digits 709 * and words. This rule set provides two variants: %traditional 710 * uses the traditional CJK numerals (which are also used in China 711 * and Korea). %financial uses alternate ideographs for many numbers 712 * that are harder to alter than the traditional numerals (one could 713 * fairly easily change a one to 714 * a three just by adding two strokes, for example). This is also done in 715 * the other countries using Chinese idographs, but different ideographs 716 * are used in those places. 717 */ 718 public static final String japanese = 719 "%financial:\n" 720 + " \u96f6; \u58f1; \u5f10; \u53c2; \u56db; \u4f0d; \u516d; \u4e03; \u516b; \u4e5d;\n" 721 + " \u62fe[>>];\n" 722 + " 20: <<\u62fe[>>];\n" 723 + " 100: <<\u767e[>>];\n" 724 + " 1000: <<\u5343[>>];\n" 725 + " 10,000: <<\u4e07[>>];\n" 726 + " 100,000,000: <<\u5104[>>];\n" 727 + " 1,000,000,000,000: <<\u5146[>>];\n" 728 + " 10,000,000,000,000,000: =#,##0=;\n" 729 + "%traditional:\n" 730 + " \u96f6; \u4e00; \u4e8c; \u4e09; \u56db; \u4e94; \u516d; \u4e03; \u516b; \u4e5d;\n" 731 + " \u5341[>>];\n" 732 + " 20: <<\u5341[>>];\n" 733 + " 100: <<\u767e[>>];\n" 734 + " 1000: <<\u5343[>>];\n" 735 + " 10,000: <<\u4e07[>>];\n" 736 + " 100,000,000: <<\u5104[>>];\n" 737 + " 1,000,000,000,000: <<\u5146[>>];\n" 738 + " 10,000,000,000,000,000: =#,##0=;"; 739 // Can someone supply me with the right fraud-proof ideographs for 740 // Simplified and Traditional Chinese, and for Korean? Can someone 741 // supply me with information on negatives and decimals? 742 743 /** 744 * Spellout rules for Greek. Again in Greek we have to supply the words 745 * for the multiples of 100 because they can't be derived algorithmically. 746 * Also, the tens dgit changes form when followed by a ones digit: an 747 * accent mark disappears from the tens digit and moves to the ones digit. 748 * Therefore, instead of using the [] notation, we actually have to use 749 * two separate rules for each multiple of 10 to show the two forms of 750 * the word. 751 */ 752 public static final String greek = 753 "zero (incomplete data); \u03ad\u03bd\u03b1; \u03b4\u03cd\u03bf; \u03b4\u03c1\u03af\u03b1; " 754 + "\u03c4\u03ad\u03c3\u03c3\u03b5\u03c1\u03b1; \u03c0\u03ad\u03bd\u03c4\u03b5; " 755 + "\u03ad\u03be\u03b9; \u03b5\u03c0\u03c4\u03ac; \u03bf\u03ba\u03c4\u03ce; " 756 + "\u03b5\u03bd\u03bd\u03ad\u03b1;\n" 757 + "10: \u03b4\u03ad\u03ba\u03b1; " 758 + "\u03ad\u03bd\u03b4\u03b5\u03ba\u03b1; \u03b4\u03ce\u03b4\u03b5\u03ba\u03b1; " 759 + "\u03b4\u03b5\u03ba\u03b1>>;\n" 760 + "20: \u03b5\u03af\u03ba\u03bf\u03c3\u03b9; \u03b5\u03b9\u03ba\u03bf\u03c3\u03b9>>;\n" 761 + "30: \u03c4\u03c1\u03b9\u03ac\u03bd\u03c4\u03b1; \u03c4\u03c1\u03b9\u03b1\u03bd\u03c4\u03b1>>;\n" 762 + "40: \u03c3\u03b1\u03c1\u03ac\u03bd\u03c4\u03b1; \u03c3\u03b1\u03c1\u03b1\u03bd\u03c4\u03b1>>;\n" 763 + "50: \u03c0\u03b5\u03bd\u03ae\u03bd\u03c4\u03b1; \u03c0\u03b5\u03bd\u03b7\u03bd\u03c4\u03b1>>;\n" 764 + "60: \u03b5\u03be\u03ae\u03bd\u03c4\u03b1; \u03b5\u03be\u03b7\u03bd\u03c4\u03b1>>;\n" 765 + "70: \u03b5\u03b2\u03b4\u03bf\u03bc\u03ae\u03bd\u03c4\u03b1; " 766 + "\u03b5\u03b2\u03b4\u03bf\u03bc\u03b7\u03bd\u03c4\u03b1>>;\n" 767 + "80: \u03bf\u03b3\u03b4\u03cc\u03bd\u03c4\u03b1; \u03bf\u03b3\u03b4\u03bf\u03bd\u03c4\u03b1>>;\n" 768 + "90: \u03b5\u03bd\u03bd\u03b5\u03bd\u03ae\u03bd\u03c4\u03b1; " 769 + "\u03b5\u03bd\u03bd\u03b5\u03bd\u03b7\u03bd\u03c4\u03b1>>;\n" 770 + "100: \u03b5\u03ba\u03b1\u03c4\u03cc[\u03bd >>];\n" 771 + "200: \u03b4\u03b9\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 772 + "300: \u03c4\u03c1\u03b9\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 773 + "400: \u03c4\u03b5\u03c4\u03c1\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 774 + "500: \u03c0\u03b5\u03bd\u03c4\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 775 + "600: \u03b5\u03be\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 776 + "700: \u03b5\u03c0\u03c4\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 777 + "800: \u03bf\u03ba\u03c4\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 778 + "900: \u03b5\u03bd\u03bd\u03b9\u03b1\u03ba\u03cc\u03c3\u03b9\u03b1[ >>];\n" 779 + "1000: \u03c7\u03af\u03bb\u03b9\u03b1[ >>];\n" 780 + "2000: << \u03c7\u03af\u03bb\u03b9\u03b1[ >>];\n" 781 + "1,000,000: << \u03b5\u03ba\u03b1\u03c4\u03bf\u03bc\u03bc\u03b9\u03cc\u03c1\u03b9\u03bf[ >>];\n" 782 + "1,000,000,000: << \u03b4\u03b9\u03c3\u03b5\u03ba\u03b1\u03c4\u03bf\u03bc\u03bc\u03b9\u03cc\u03c1\u03b9\u03bf[ >>];\n" 783 + "1,000,000,000,000: =#,##0="; 784 // Can someone supply me with information on negatives and decimals? 785 // I'm also missing the word for zero. Can someone clue me in? 786 787 /** 788 * Spellout rules for Russian. 789 */ 790 public static final String russian = 791 "\u043d\u043e\u043b\u044c; \u043e\u0434\u0438\u043d; \u0434\u0432\u0430; \u0442\u0440\u0438; " 792 + "\u0447\u0435\u0442\u044b\u0440\u0435; \u043f\u044f\u0442; \u0448\u0435\u0441\u0442; " 793 + "\u0441\u0435\u043c\u044c; \u0432\u043e\u0441\u0435\u043c\u044c; \u0434\u0435\u0432\u044f\u0442;\n" 794 + "10: \u0434\u0435\u0441\u044f\u0442; " 795 + "\u043e\u0434\u0438\u043d\u043d\u0430\u0434\u0446\u0430\u0442\u044c;\n" 796 + "\u0434\u0432\u0435\u043d\u043d\u0430\u0434\u0446\u0430\u0442\u044c; " 797 + "\u0442\u0440\u0438\u043d\u0430\u0434\u0446\u0430\u0442\u044c; " 798 + "\u0447\u0435\u0442\u044b\u0440\u043d\u0430\u0434\u0446\u0430\u0442\u044c;\n" 799 + "15: \u043f\u044f\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c; " 800 + "\u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c; " 801 + "\u0441\u0435\u043c\u043d\u0430\u0434\u0446\u0430\u0442\u044c; " 802 + "\u0432\u043e\u0441\u0435\u043c\u043d\u0430\u0434\u0446\u0430\u0442\u044c; " 803 + "\u0434\u0435\u0432\u044f\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c;\n" 804 + "20: \u0434\u0432\u0430\u0434\u0446\u0430\u0442\u044c[ >>];\n" 805 + "30: \u0442\u0440\u043b\u0434\u0446\u0430\u0442\u044c[ >>];\n" 806 + "40: \u0441\u043e\u0440\u043e\u043a[ >>];\n" 807 + "50: \u043f\u044f\u0442\u044c\u0434\u0435\u0441\u044f\u0442[ >>];\n" 808 + "60: \u0448\u0435\u0441\u0442\u044c\u0434\u0435\u0441\u044f\u0442[ >>];\n" 809 + "70: \u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u0442[ >>];\n" 810 + "80: \u0432\u043e\u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u0442[ >>];\n" 811 + "90: \u0434\u0435\u0432\u044f\u043d\u043e\u0441\u0442\u043e[ >>];\n" 812 + "100: \u0441\u0442\u043e[ >>];\n" 813 + "200: << \u0441\u0442\u043e[ >>];\n" 814 + "1000: \u0442\u044b\u0441\u044f\u0447\u0430[ >>];\n" 815 + "2000: << \u0442\u044b\u0441\u044f\u0447\u0430[ >>];\n" 816 + "1,000,000: \u043c\u0438\u043b\u043b\u0438\u043e\u043d[ >>];\n" 817 + "2,000,000: << \u043c\u0438\u043b\u043b\u0438\u043e\u043d[ >>];\n" 818 + "1,000,000,000: =#,##0=;"; 819 // Can someone supply me with information on negatives and decimals? 820 // How about words for billions and trillions? 821 822 /** 823 * Spellout rules for Hebrew. Hebrew actually has inflected forms for 824 * most of the lower-order numbers. The masculine forms are shown 825 * here. 826 */ 827 public static final String hebrew = 828 "zero (incomplete data); \u05d0\u05d4\u05d3; \u05e9\u05d2\u05d9\u05d9\u05dd; \u05e9\u05dc\u05d5\u05e9\u05d4;\n" 829 + "4: \u05d0\u05d3\u05d1\u05e6\u05d4; \u05d7\u05d2\u05d5\u05d9\u05e9\u05d4; \u05e9\u05e9\u05d4;\n" 830 + "7: \u05e9\u05d1\u05e6\u05d4; \u05e9\u05de\u05d5\u05d2\u05d4; \u05ea\u05e9\u05e6\u05d4;\n" 831 + "10: \u05e6\u05e9\u05d3\u05d4[ >>];\n" 832 + "20: \u05e6\u05e9\u05d3\u05d9\u05dd[ >>];\n" 833 + "30: \u05e9\u05dc\u05d5\u05e9\u05d9\u05dd[ >>];\n" 834 + "40: \u05d0\u05d3\u05d1\u05e6\u05d9\u05dd[ >>];\n" 835 + "50: \u05d7\u05de\u05d9\u05e9\u05d9\u05dd[ >>];\n" 836 + "60: \u05e9\u05e9\u05d9\u05dd[ >>];\n" 837 + "70: \u05e9\u05d1\u05e6\u05d9\u05dd[ >>];\n" 838 + "80: \u05e9\u05de\u05d5\u05d2\u05d9\u05dd[ >>];\n" 839 + "90: \u05ea\u05e9\u05e6\u05d9\u05dd[ >>];\n" 840 + "100: \u05de\u05d0\u05d4[ >>];\n" 841 + "200: << \u05de\u05d0\u05d4[ >>];\n" 842 + "1000: \u05d0\u05dc\u05e3[ >>];\n" 843 + "2000: << \u05d0\u05dc\u05e3[ >>];\n" 844 + "1,000,000: =#,##0= (incomplete data);"; 845 // This data is woefully incomplete. Can someone fill me in on the 846 // various inflected forms of the numbers, which seem to be necessary 847 // to do Hebrew correctly? Can somone supply me with data for values 848 // from 1,000,000 on up? What about the word for zero? What about 849 // information on negatives and decimals? 850 851 //======================================================================== 852 // Simple examples 853 //======================================================================== 854 855 /** 856 * This rule set adds an English ordinal abbreviation to the end of a 857 * number. For example, 2 is formatted as "2nd". Parsing doesn't work with 858 * this rule set. To parse, use DecimalFormat on the numeral. 859 */ 860 public static final String ordinal = 861 // this rule set formats the numeral and calls %%abbrev to 862 // supply the abbreviation 863 "%main:\n" 864 + " =#,##0==%%abbrev=;\n" 865 // this rule set supplies the abbreviation 866 + "%%abbrev:\n" 867 // the abbreviations. Everything from 4 to 19 ends in "th" 868 + " th; st; nd; rd; th;\n" 869 // at 20, we begin repeating the cycle every 10 (13 is "13th", 870 // but 23 and 33 are "23rd" and "33rd") We do this by 871 // ignoring all bug the ones digit in selecting the abbreviation 872 + " 20: >>;\n" 873 // at 100, we repeat the whole cycle by considering only the 874 // tens and ones digits in picking an abbreviation 875 + " 100: >>;\n"; 876 877 /** 878 * This is a simple message-formatting example. Normally one would 879 * use ChoiceFormat and MessageFormat to do something this simple, 880 * but this shows it could be done with RuleBasedNumberFormat too. 881 * A message-formatting example that might work better with 882 * RuleBasedNumberFormat appears later. 883 */ 884 public static final String message1 = 885 // this rule surrounds whatever the other rules produce with the 886 // rest of the sentence 887 "x.0: The search found <<.;\n" 888 // use words for values below 10 (and change to "file" for 1) 889 + "no files; one file; two files; three files; four files; five files;\n" 890 + " six files; seven files; eight files; nine files;\n" 891 // use numerals for values higher than 10 892 + "=#,##0= files;"; 893 894 //======================================================================== 895 // Fraction handling 896 // 897 // The next few examples show how RuleBasedNumberFormat can be used for 898 // more flexible handling of fractions 899 //======================================================================== 900 901 /** 902 * This example formats a number in one of the two styles often used 903 * on checks. %dollars-and-hundredths formats cents as hundredths of 904 * a dollar (23.40 comes out as "twenty-three and 40/100 dollars"). 905 * %dollars-and-cents formats in dollars and cents (23.40 comes out as 906 * "twenty-three dollars and forty cents") 907 */ 908 public static final String dollarsAndCents = 909 // this rule set formats numbers as dollars and cents 910 "%dollars-and-cents:\n" 911 // if the value is 1 or more, put "xx dollars and yy cents". 912 // the "and y cents" part is suppressed if the value is an 913 // even number of dollars 914 + " x.0: << [and >%%cents>];\n" 915 // if the value is between 0 and 1, put "xx cents" 916 + " 0.x: >%%cents>;\n" 917 // these three rules take care of the singular and plural 918 // forms of "dollar" and use %%main to format the number 919 + " 0: zero dollars; one dollar; =%%main= dollars;\n" 920 // these are the regular U.S. English number spellout rules 921 + "%%main:\n" 922 + " zero; one; two; three; four; five; six; seven; eight; nine;\n" 923 + " ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n" 924 + " seventeen; eighteen; nineteen;\n" 925 + " 20: twenty[->>];\n" 926 + " 30: thirty[->>];\n" 927 + " 40: forty[->>];\n" 928 + " 50: fifty[->>];\n" 929 + " 60: sixty[->>];\n" 930 + " 70: seventy[->>];\n" 931 + " 80: eighty[->>];\n" 932 + " 90: ninety[->>];\n" 933 + " 100: << hundred[ >>];\n" 934 + " 1000: << thousand[ >>];\n" 935 + " 1,000,000: << million[ >>];\n" 936 + " 1,000,000,000: << billion[ >>];\n" 937 + " 1,000,000,000,000: << trillion[ >>];\n" 938 + " 1,000,000,000,000,000: =#,##0=;\n" 939 // this rule takes care of the fractional part of the value. It 940 // multiplies the fractional part of the number being formatted by 941 // 100, formats it with %%main, and then addes the word "cent" or 942 // "cents" to the end. (The text in brackets is omitted if the 943 // numerator of the fraction is 1.) 944 + "%%cents:\n" 945 + " 100: <%%main< cent[s];\n" 946 947 // this rule set formats numbers as dollars and hundredths of dollars 948 + "%dollars-and-hundredths:\n" 949 // this rule takes care of the general shell of the output 950 // string. We always show the cents, even when there aren't 951 // any. Because of this, the word is always "dollars"-- 952 // we don't have to worry about the singular form. We use 953 // %%main to format the number of dollars and %%hundredths to 954 // format the number of cents 955 + " x.0: <%%main< and >%%hundredths>/100 dollars;\n" 956 // this rule set formats the cents for %dollars-and-hundredths. 957 // It multiplies the fractional part of the number by 100 and formats 958 // the result using a DecimalFormat ("00" tells the DecimalFormat to 959 // always use two digits, even for numbers under 10) 960 + "%%hundredths:\n" 961 + " 100: <00<;\n"; 962 963 /** 964 * This rule set shows the fractional part of the number as a fraction 965 * with a power of 10 as the denominator. Some languages don't spell 966 * out the fractional part of a number as "point one two three," but 967 * always render it as a fraction. If we still want to treat the fractional 968 * part of the number as a decimal, then the fraction's denominator 969 * is always a power of 10. This example does that: 23.125 is formatted 970 * as "twenty-three and one hundred twenty-five thousandths" (as opposed 971 * to "twenty-three point one two five" or "twenty-three and one eighth"). 972 */ 973 public static final String decimalAsFraction = 974 // the regular U.S. English spellout rules, with one difference 975 "%main:\n" 976 + " -x: minus >>;\n" 977 // the difference. This rule uses %%frac to show the fractional 978 // part of the number. Text in brackets is omitted when the 979 // value is between 0 and 1 (causing 0.3 to come out as "three 980 // tenths" instead of "zero and three tenths"). 981 + " x.x: [<< and ]>%%frac>;\n" 982 + " zero; one; two; three; four; five; six; seven; eight; nine;\n" 983 + " ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n" 984 + " seventeen; eighteen; nineteen;\n" 985 + " twenty[->>];\n" 986 + " 30: thirty[->>];\n" 987 + " 40: forty[->>];\n" 988 + " 50: fifty[->>];\n" 989 + " 60: sixty[->>];\n" 990 + " 70: seventy[->>];\n" 991 + " 80: eighty[->>];\n" 992 + " 90: ninety[->>];\n" 993 + " 100: << hundred[ >>];\n" 994 + " 1000: << thousand[ >>];\n" 995 + " 1,000,000: << million[ >>];\n" 996 + " 1,000,000,000: << billion[ >>];\n" 997 + " 1,000,000,000,000: << trillion[ >>];\n" 998 + " 1,000,000,000,000,000: =#,##0=;\n" 999 // the rule set that formats the fractional part of the number. 1000 // The rule that is used is the one that, when its baase value is 1001 // multiplied by the fractional part of the number being formatted, 1002 // produces the result closest to zero. Thus, the base values are 1003 // prospective denominators of the fraction. The << marks the place 1004 // where the numerator of the fraction (the result of multiplying the 1005 // fractional part of the number by the rule's base value) is 1006 // placed. Text in brackets is omitted when the numerator is 1, giving 1007 // us the singular and plural forms of the words. 1008 // [In languages where the singular and plural are completely different 1009 // words, the rule can just be stated twice: the second time with 1010 // the plural form.] 1011 + "%%frac:\n" 1012 + " 10: << tenth[s];\n" 1013 + " 100: << hundredth[s];\n" 1014 + " 1000: << thousandth[s];\n" 1015 + " 10,000: << ten-thousandth[s];\n" 1016 + " 100,000: << hundred-thousandth[s];\n" 1017 + " 1,000,000: << millionth[s];"; 1018 1019 /** 1020 * Number with closest fraction. This example formats a value using 1021 * numerals, but shows the fractional part as a ratio (fraction) rather 1022 * than a decimal. The fraction always has a denominator between 2 and 10. 1023 */ 1024 public static final String closestFraction = 1025 "%main:\n" 1026 // this rule formats the number if it's 1 or more. It formats 1027 // the integral part using a DecimalFormat ("#,##0" puts 1028 // thousands separators in the right places) and the fractional 1029 // part using %%frac. If there is no fractional part, it 1030 // just shows the integral part. 1031 + " x.0: <#,##0<[ >%%frac>];\n" 1032 // this rule formats the number if it's between 0 and 1. It 1033 // shows only the fractional part (0.5 shows up as "1/2," not 1034 // "0 1/2") 1035 + " 0.x: >%%frac>;\n" 1036 // the fraction rule set. This works the same way as the one in the 1037 // preceding example: We multiply the fractional part of the number 1038 // being formatted by each rule's base value and use the rule that 1039 // produces the result closest to 0 (or the first rule that produces 0). 1040 // Since we only provide rules for the numbers from 2 to 10, we know 1041 // we'll get a fraction with a denominator between 2 and 10. 1042 // "<0<" causes the numerator of the fraction to be formatted 1043 // using numerals 1044 + "%%frac:\n" 1045 + " 2: 1/2;\n" 1046 + " 3: <0</3;\n" 1047 + " 4: <0</4;\n" 1048 + " 5: <0</5;\n" 1049 + " 6: <0</6;\n" 1050 + " 7: <0</7;\n" 1051 + " 8: <0</8;\n" 1052 + " 9: <0</9;\n" 1053 + " 10: <0</10;\n"; 1054 1055 /** 1056 * American stock-price formatting. Non-integral stock prices are still 1057 * generally shown in eighths or sixteenths of dollars instead of dollars 1058 * and cents. This example formats stock prices in this way if possible, 1059 * and in dollars and cents if not. 1060 */ 1061 public static final String stock = 1062 "%main:\n" 1063 // this rule formats the integral part of the number in numerals 1064 // and (if necessary) the fractional part using %%frac1 1065 + " x.0: <#,##0<[>%%frac1>];\n" 1066 // this rule is used for values between 0 and 1 and omits the 1067 // integral part 1068 + " 0.x: >%%frac2>;\n" 1069 // this rule set is used to format the fractional part of the number when 1070 // there's an integral part before it (again, we try all denominators 1071 // and use the "best" one) 1072 + "%%frac1:\n" 1073 // for even multiples of 1/4, format the fraction using the 1074 // typographer's fractions 1075 + " 4: <%%quarters<;\n" 1076 // format the value as a number of eighths, sixteenths, or 1077 // thirty-seconds, whichever produces the most accurate value. 1078 // The apostrophe at the front of these rules is ignored, but 1079 // it makes the space that follows it significant. This puts a 1080 // space between the value's integral and fractional parts so 1081 // you can read it 1082 + " 8: ' <0</8;\n" 1083 + " 16: ' <0</16;\n" 1084 + " 32: ' <0</32;\n" 1085 // if we can't reasonably format the number in powers of 2, 1086 // then show it as dollars and cents 1087 + " 100: .<00<;\n" 1088 // this rule set is used when the fractional part of the value stands 1089 // alone 1090 + "%%frac2:\n" 1091 + " 4: <%%quarters<;\n" 1092 // for fractions that we can't show using typographer's fractions, 1093 // we don't have to put a space before the fraction 1094 + " 8: <0</8;\n" 1095 + " 16: <0</16;\n" 1096 + " 32: <0</32;\n" 1097 // but dollars and cents look better with a leading 0 1098 + " 100: 0.<00<;\n" 1099 // this rule set formats 1/4, 1/2, and 3/4 using typographer's fractions 1100 + "%%quarters:\n" 1101 + " ; \u00bc; \u00bd; \u00be;\n" 1102 // there are the lenient-parse rules. These allow the user to type 1103 // "1/4," "1/2," and "3/4" instead of their typographical counterparts 1104 // and still have them be understood by the formatter 1105 + "%%lenient-parse:\n" 1106 + " & '1/4' , \u00bc\n" 1107 + " & '1/2' , \u00bd\n" 1108 + " & '3/4' , \u00be\n;"; 1109 1110 //======================================================================== 1111 // Changing dimensions 1112 // 1113 // The next few examples demonstrate using a RuleBasedNumberFormat to 1114 // change the units a value is denominated in depending on its magnitude 1115 //======================================================================== 1116 1117 /** 1118 * The example shows large numbers the way they often appear is nwespapers: 1119 * 1,200,000 is formatted as "1.2 million". 1120 */ 1121 public static final String abbEnglish = 1122 "=#,##0=;\n" 1123 // this is fairly self-explanatory, but note that the << substitution 1124 // can show the fractional part of the substitution value if the user 1125 // wants it 1126 + "1,000,000: <##0.###< million;\n" 1127 + "1,000,000,000: <##0.###< billion;\n" 1128 + "1,000,000,000,000: <##0.###< trillion;\n"; 1129 1130 /** 1131 * This example takes a number of meters and formats it in whatever unit 1132 * will produce a number with from one to three digits before the decimal 1133 * point. For example, 230,000 is formatted as "230 km". 1134 */ 1135 public static final String units = 1136 "%main:\n" 1137 // for values between 0 and 1, delegate to %%small 1138 + " 0.x: >%%small>;\n" 1139 // otherwise, show between 3 and 6 significant digits of the value 1140 // along with the most appropriate unit 1141 + " 0: =##0.###= m;\n" 1142 + " 1,000: <##0.###< km;\n" 1143 + " 1,000,000: <##0.###< Mm;\n" 1144 + " 1,000,000,000: <##0.###< Gm;\n" 1145 + " 1,000,000,000,000: <#,##0.###< Tm;\n" 1146 // %%small formats the number when it's less then 1. It multiplies the 1147 // value by one billion, and then uses %%small2 to actually do the 1148 // formatting. 1149 + "%%small:\n" 1150 + " 1,000,000,000,000: <%%small2<;\n" 1151 // this rule set actually formats small values. %%small passes this 1152 // rule set a number of picometers, and it takes care of scaling up as 1153 // appropriate in exactly the same way %main does (we can't normally 1154 // handle fractional values this way: here, we're concerned about 1155 // magnitude; most of the time, we're concerned about precsion) 1156 + "%%small2:\n" 1157 + " 0: =##0= pm;\n" 1158 + " 1,000: <##0.###< nm;\n" 1159 + " 1,000,000: <##0.###< \u00b5m;\n" 1160 + " 1,000,000,000: <##0.###< mm;\n"; 1161 1162 /** 1163 * A more complicated message-formatting example. Here, in addition to 1164 * handling the singular and plural versions of the word, the value is 1165 * denominated in bytes, kilobytes, or megabytes depending on its magnitude. 1166 * Also notice that it correctly treats a kilobyte as 1,024 bytes (not 1,000), 1167 * and a megabyte as 1,024 kilobytes (not 1,000). 1168 */ 1169 public static final String message2 = 1170 // this rule supplies the shell of the sentence 1171 "x.0: There << free space on the disk.;\n" 1172 // handle singular and plural forms of "byte" (and format 0 as 1173 // "There is no free space...") 1174 + "0: is no;\n" 1175 + "is one byte of;\n" 1176 + "are =0= bytes of;\n" 1177 // for values above 1,024, format the number in K (since "K" is usually 1178 // promounced "K" regardless of whether it's singular or plural, we 1179 // don't worry about the plural form). The "/1024" here causes us to 1180 // treat a K as 1,024 bytes rather than 1,000 bytes. 1181 + "1024/1024: is <0<K of;\n" 1182 // for values about 1,048,576, format the number in Mb. Since "Mb" is 1183 // usually promounced "meg" in singular and "megs" in plural, we do have 1184 // both singular and plural forms. Again, notice we treat a megabyte 1185 // as 1,024 kilobytes. 1186 + "1,048,576/1024: is 1 Mb of;\n" 1187 + "2,097,152/1024: are <0< Mb of;"; 1188 1189 //======================================================================== 1190 // Alternate radices 1191 //======================================================================== 1192 1193 /** 1194 * This example formats a number in dozens and gross. This is intended to 1195 * demonstrate how this rule set can be used to format numbers in systems 1196 * other than base 10. The "/12" after the rules' base values controls this. 1197 * Also notice that the base doesn't have to be consistent throughout the 1198 * whole rule set: we go back to base 10 for values over 1,000. 1199 */ 1200 public static final String dozens = 1201 // words for numbers... 1202 "zero; one; two; three; four; five; six;\n" 1203 + "seven; eight; nine; ten; eleven;\n" 1204 // format values over 12 in dozens 1205 + "12/12: << dozen[ and >>];\n" 1206 // format values over 144 in gross 1207 + "144/12: << gross[, >>];\n" 1208 // format values over 1,000 in thousands 1209 + "1000: << thousand[, >>];\n" 1210 // overflow rule. Format values over 10,000 in numerals 1211 + "10,000: =#,##0=;\n"; 1212 1213 //======================================================================== 1214 // Major and minor units 1215 // 1216 // These examples show how a single value can be divided up into major 1217 // and minor units that don't relate to each other by a factor of 10. 1218 //======================================================================== 1219 1220 /** 1221 * This example formats a number of seconds in sexagesimal notation 1222 * (i.e., hours, minutes, and seconds). %with-words formats it with 1223 * words (3740 is "1 hour, 2 minutes, 20 seconds") and %in-numerals 1224 * formats it entirely in numerals (3740 is "1:02:20"). 1225 */ 1226 public static final String durationInSeconds = 1227 // main rule set for formatting with words 1228 "%with-words:\n" 1229 // take care of singular and plural forms of "second" 1230 + " 0 seconds; 1 second; =0= seconds;\n" 1231 // use %%min to format values greater than 60 seconds 1232 + " 60/60: <%%min<[, >>];\n" 1233 // use %%hr to format values greater than 3,600 seconds 1234 // (the ">>>" below causes us to see the number of minutes 1235 // when when there are zero minutes) 1236 + " 3600/60: <%%hr<[, >>>];\n" 1237 // this rule set takes care of the singular and plural forms 1238 // of "minute" 1239 + "%%min:\n" 1240 + " 0 minutes; 1 minute; =0= minutes;\n" 1241 // this rule set takes care of the singular and plural forms 1242 // of "hour" 1243 + "%%hr:\n" 1244 + " 0 hours; 1 hour; =0= hours;\n" 1245 1246 // main rule set for formatting in numerals 1247 + "%in-numerals:\n" 1248 // values below 60 seconds are shown with "sec." 1249 + " =0= sec.;\n" 1250 // higher values are shown with colons: %%min-sec is used for 1251 // values below 3,600 seconds... 1252 + " 60: =%%min-sec=;\n" 1253 // ...and %%hr-min-sec is used for values of 3,600 seconds 1254 // and above 1255 + " 3600: =%%hr-min-sec=;\n" 1256 // this rule causes values of less than 10 minutes to show without 1257 // a leading zero 1258 + "%%min-sec:\n" 1259 + " 0: :=00=;\n" 1260 + " 60/60: <0<>>;\n" 1261 // this rule set is used for values of 3,600 or more. Minutes are always 1262 // shown, and always shown with two digits 1263 + "%%hr-min-sec:\n" 1264 + " 0: :=00=;\n" 1265 + " 60/60: <00<>>;\n" 1266 + " 3600/60: <#,##0<:>>>;\n" 1267 // the lenient-parse rules allow several different characters to be used 1268 // as delimiters between hours, minutes, and seconds 1269 + "%%lenient-parse:\n" 1270 + " & : = . = ' ' = -;\n"; 1271 1272 /** 1273 * This example formats a number of hours in sexagesimal notation (i.e., 1274 * hours, minutes, and seconds). %with-words formats the value using 1275 * words for the units, and %in-numerals formats the value using only 1276 * numerals. 1277 */ 1278 public static final String durationInHours = 1279 // main entry point for formatting with words 1280 "%with-words:\n" 1281 // this rule omits minutes and seconds when the value is 1282 // an even number of hours 1283 + " x.0: <<[, >%%min-sec>];\n" 1284 // these rules take care of the singular and plural forms 1285 // of hours 1286 + " 0 hours; 1 hour; =#,##0= hours;\n" 1287 // this rule set takes the fractional part of the number and multiplies 1288 // it by 3,600 (turning it into a number of seconds). Then it delegates 1289 // to %%min-sec-implementation to format the resulting value 1290 + "%%min-sec:\n" 1291 + " 3600: =%%min-sec-implementation=;\n" 1292 // this rule set formats the seconds as either seconds or minutes and 1293 // seconds, and takes care of the singular and plural forms of 1294 // "minute" and "second" 1295 + "%%min-sec-implementation:\n" 1296 + " 0 seconds; 1 second; =0= seconds;\n" 1297 + " 60/60: 1 minute[, >>];\n" 1298 + " 120/60: <0< minutes[, >>];\n" 1299 1300 // main entry point for formatting in numerals 1301 + "%in-numerals:\n" 1302 // show minutes even for even numbers of hours 1303 + " x.0: <#,##0<:00;\n" 1304 // delegate to %%min-sec2 to format minutes and seconds 1305 + " x.x: <#,##0<:>%%min-sec2>;\n" 1306 // this rule set formats minutes when there is an even number of 1307 // minutes, and delegates to %%min-sec2-implementation when there 1308 // are seconds 1309 + "%%min-sec2:\n" 1310 + " 60: <00<;\n" 1311 + " 3600: <%%min-sec2-implementation<;\n" 1312 // these two rule sets are used to format the minutes and seconds 1313 + "%%min-sec2-implementation:\n" 1314 // if there are fewer than 60 seconds, show the minutes anyway 1315 + " 0: 00:=00=;\n" 1316 // if there are minutes, format them too, and always use 2 digits 1317 // for both minutes and seconds 1318 + " 60: =%%min-sec3=;\n" 1319 + "%%min-sec3:\n" 1320 + " 0: :=00=;\n" 1321 + " 60/60: <00<>>;\n" 1322 // the lenient-parse rules allow the user to use any of several 1323 // characters as delimiters between hours, minutes, and seconds 1324 + "%%lenient-parse:\n" 1325 + " & : = . = ' ' = -;\n"; 1326 1327 /** 1328 * This rule set formats a number of pounds as pounds, shillings, and 1329 * pence in the old English system of currency. 1330 */ 1331 public static final String poundsShillingsAndPence = 1332 // for values of 1 or more, format the integral part with a pound 1333 // sign in front, and show shillings and pence if necessary 1334 "%main:\n" 1335 + " x.0: \u00a3<#,##0<[ >%%shillings-and-pence>];\n" 1336 // for values between 0 and 1, omit the number of pounds 1337 + " 0.x: >%%pence-alone>;\n" 1338 // this rule set is used to show shillings and pence. It multiplies 1339 // the fractional part of the number by 240 (the number of pence in a 1340 // pound) and uses %%shillings-and-pence-implementation to format 1341 // the result 1342 + "%%shillings-and-pence:\n" 1343 + " 240: <%%shillings-and-pence-implementation<;\n" 1344 // this rule set is used to show shillings and pence when there are 1345 // no pounds. It also multiplies the value by 240, and then it uses 1346 // %%pence-alone-implementation to format the result. 1347 + "%%pence-alone:\n" 1348 + " 240: <%%pence-alone-implementation<;\n" 1349 // this rule set formats a number of pence when we know we also 1350 // have pounds. We always show shillings (with a 0 if necessary), 1351 // but only show pence if the value isn't an even number of shillings 1352 + "%%shillings-and-pence-implementation:\n" 1353 + " 0/; 0/=0=;\n" 1354 + " 12/12: <0</[>0>];\n" 1355 // this rule set formats a number of pence when we know there are 1356 // no pounds. Values less than a shilling are shown with "d." (the 1357 // abbreviation for pence), and values greater than a shilling are 1358 // shown with a shilling bar (and without pence when the value is 1359 // an even number of shillings) 1360 + "%%pence-alone-implementation:\n" 1361 + " =0= d.;\n" 1362 + " 12/12: <0</[>0>];\n"; 1363 1364 //======================================================================== 1365 // Alternate numeration systems 1366 // 1367 // These examples show how RuleBasedNumberFormat can be used to format 1368 // numbers using non-positional numeration systems. 1369 //======================================================================== 1370 1371 /** 1372 * Arabic digits. This example formats numbers in Arabic numerals. 1373 * Normally, you'd do this with DecimalFormat, but this shows that 1374 * RuleBasedNumberFormat can handle it too. 1375 */ 1376 public static final String arabicNumerals = 1377 "0; 1; 2; 3; 4; 5; 6; 7; 8; 9;\n" 1378 + "10: <<>>;\n" 1379 + "100: <<>>>;\n" 1380 + "1000: <<,>>>;\n" 1381 + "1,000,000: <<,>>>;\n" 1382 + "1,000,000,000: <<,>>>;\n" 1383 + "1,000,000,000,000: <<,>>>;\n" 1384 + "1,000,000,000,000,000: =#,##0=;\n" 1385 + "-x: ->>;\n" 1386 + "x.x: <<.>>;"; 1387 1388 /** 1389 * Words for digits. Follows the same pattern as the Arabic-numerals 1390 * example above, but uses words for the various digits (e.g., 123 comes 1391 * out as "one two three"). 1392 */ 1393 public static final String wordsForDigits = 1394 "-x: minus >>;\n" 1395 + "x.x: << point >>;\n" 1396 + "zero; one; two; three; four; five; six;\n" 1397 + " seven; eight; nine;\n" 1398 + "10: << >>;\n" 1399 + "100: << >>>;\n" 1400 + "1000: <<, >>>;\n" 1401 + "1,000,000: <<, >>>;\n" 1402 + "1,000,000,000: <<, >>>;\n" 1403 + "1,000,000,000,000: <<, >>>;\n" 1404 + "1,000,000,000,000,000: =#,##0=;\n"; 1405 1406 /** 1407 * This example formats numbers using Chinese characters in the Arabic 1408 * place-value method. This was used historically in China for a while. 1409 */ 1410 public static final String chinesePlaceValue = 1411 "\u3007; \u4e00; \u4e8c; \u4e09; \u56db; \u4e94; \u516d; \u4e03; \u516b; \u4e5d;\n" 1412 + "10: <<>>;\n" 1413 + "100: <<>>>;\n" 1414 + "1000: <<>>>;\n" 1415 + "1,000,000: <<>>>;\n" 1416 + "1,000,000,000: <<>>>;\n" 1417 + "1,000,000,000,000: <<>>>;\n" 1418 + "1,000,000,000,000,000: =#,##0=;\n"; 1419 1420 /** 1421 * Roman numerals. This example has two variants: %modern shows how large 1422 * numbers are usually handled today; %historical ses the older symbols for 1423 * thousands. 1424 */ 1425 public static final String romanNumerals = 1426 "%historical:\n" 1427 + " =%modern=;\n" 1428 // in early Roman numerals, 1,000 was shown with a circle 1429 // bisected by a vertical line. Additional thousands were 1430 // shown by adding more concentric circles, and fives were 1431 // shown by cutting the symbol for next-higher power of 10 1432 // in half (the letter D for 500 evolved from this). 1433 // We could go beyond 40,000, but Unicode doesn't encode 1434 // the symbols for higher numbers/ 1435 + " 1000: \u2180[>>]; 2000: \u2180\u2180[>>]; 3000: \u2180\u2180\u2180[>>]; 4000: \u2180\u2181[>>];\n" 1436 + " 5000: \u2181[>>]; 6000: \u2181\u2180[>>]; 7000: \u2181\u2180\u2180[>>];\n" 1437 + " 8000: \u2181\u2180\u2180\u2180[>>]; 9000: \u2180\u2182[>>];\n" 1438 + " 10,000: \u2182[>>]; 20,000: \u2182\u2182[>>]; 30,000: \u2182\u2182\u2182[>>];\n" 1439 + " 40,000: =#,##0=;\n" 1440 + "%modern:\n" 1441 + " ; I; II; III; IV; V; VI; VII; VIII; IX;\n" 1442 + " 10: X[>>]; 20: XX[>>]; 30: XXX[>>]; 40: XL[>>]; 50: L[>>];\n" 1443 + " 60: LX[>>]; 70: LXX[>>]; 80: LXXX[>>]; 90: XC[>>];\n" 1444 + " 100: C[>>]; 200: CC[>>]; 300: CCC[>>]; 400: CD[>>]; 500: D[>>];\n" 1445 + " 600: DC[>>]; 700: DCC[>>]; 800: DCCC[>>]; 900: CM[>>];\n" 1446 // in modern Roman numerals, high numbers are generally shown 1447 // by placing a bar over the letters for the lower numbers: 1448 // the bar multiplied a letter's value by 1,000 1449 + " 1000: M[>>]; 2000: MM[>>]; 3000: MMM[>>]; 4000: MV\u0306[>>];\n" 1450 + " 5000: V\u0306[>>]; 6000: V\u0306M[>>]; 7000: V\u0306MM[>>];\n" 1451 + " 8000: V\u0306MMM[>>]; 9000: MX\u0306[>>];\n" 1452 + " 10,000: X\u0306[>>]; 20,000: X\u0306X\u0306[>>]; 30,000: X\u0306X\u0306X\u0306[>>];\n" 1453 + " 40,000: X\u0306L\u0306[>>]; 50,000: L\u0306[>>]; 60,000: L\u0306X\u0306[>>];\n" 1454 + " 70,000: L\u0306X\u0306X\u0306[>>]; 80,000: L\u0306X\u0306X\u0306X\u0306[>>];\n" 1455 + " 90,000: X\u0306C\u0306[>>];\n" 1456 + " 100,000: C\u0306[>>]; 200,000: C\u0306C\u0306[>>]; 300,000: C\u0306C\u0306[>>];\n" 1457 + " 400,000: C\u0306D\u0306[>>]; 500,000: D\u0306[>>]; 600,000: D\u0306C\u0306[>>];\n" 1458 + " 700,000: D\u0306C\u0306C\u0306[>>]; 800,000: D\u0306C\u0306C\u0306C\u0306[>>];\n" 1459 + " 900,000: =#,##0=;\n"; 1460 1461 /** 1462 * Hebrew alphabetic numerals. Before adoption of Arabic numerals, Hebrew speakers 1463 * used the letter of their alphabet as numerals. The first nine letters of 1464 * the alphabet repesented the values from 1 to 9, the second nine letters the 1465 * multiples of 10, and the remaining letters the multiples of 100. Since they 1466 * ran out of letters at 400, the remaining multiples of 100 were represented 1467 * using combinations of the existing letters for the hundreds. Numbers were 1468 * distinguished from words in a number of different ways: the way shown here 1469 * uses a single mark after a number consisting of one letter, and a double 1470 * mark between the last two letters of a number consisting of two or more 1471 * letters. Two dots over a letter multiplied its value by 1,000. Also, since 1472 * the letter for 10 is the first letter of God's name and the letters for 5 and 6 1473 * are letters in God's name, which wasn't supposed to be written or spoken, 15 and 1474 * 16 were usually written as 9 + 6 and 9 + 7 instead of 10 + 5 and 10 + 6. 1475 */ 1476 public static final String hebrewAlphabetic = 1477 // letters for the ones 1478 "%%ones:\n" 1479 + " (no zero); \u05d0; \u05d1; \u05d2; \u05d3; \u05d4; \u05d5; \u05d6; \u05d7; \u05d8;\n" 1480 // letters for the tens 1481 + "%%tens:\n" 1482 + " ; \u05d9; \u05db; \u05dc; \u05de; \u05e0; \u05e1; \u05e2; \u05e4; \u05e6;\n" 1483 // letters for the first four hundreds 1484 + "%%hundreds:\n" 1485 + " ; \u05e7; \u05e8; \u05e9; \u05ea;\n" 1486 // this rule set is used to write the combination of the tens and ones digits 1487 // when we know that no other digits precede them: they put the numeral marks 1488 // in the right place and properly handle 15 and 16 (I'm using the mathematical 1489 // prime characters for the numeral marks because my Unicode font doesn't 1490 // include the real Hebrew characters, which look just like the prime marks) 1491 + "%%tens-and-ones:\n" 1492 // for values less than 10, just use %%ones and put the numeral mark 1493 // afterward 1494 + " =%%ones=\u2032;\n" 1495 // put the numeral mark at the end for 10, but in the middle for 1496 // 11 through 14 1497 + " 10: <%%tens<\u2032; <%%tens<\u2033>%%ones>;\n" 1498 // special-case 15 and 16 1499 + " 15: \u05d8\u2033\u05d5; 16: \u05d8\u2033\u05d6;\n" 1500 // go back to the normal method at 17 1501 + " 17: <%%tens<\u2033>%%ones>;\n" 1502 // repeat the rules for 10 and 11 to cover the values from 20 to 99 1503 + " 20: <%%tens<\u2032; <%%tens<\u2033>%%ones>;\n" 1504 // this rule set is used to format numbers below 1,000. It relies on 1505 // %%tens-and-ones to format the tens and ones places, and adds logic 1506 // to handle the high hundreds and the numeral marks when there is no 1507 // tens digit. Notice how the rules are paired: all of these pairs of 1508 // rules take advantage of the rollback rule: if the value (between 100 1509 // and 499) is an even multiple of 100, the rule for 100 is used; otherwise, 1510 // the rule for 101 (the following rule) is used. The first rule in each 1511 // pair (the one for the even multiple) places the numeral mark in a different 1512 // spot than the second rule in each pair (which knows there are more digits 1513 // and relies on the rule supplying them to also supply the numeral mark). 1514 // The call to %%null in line 10 is there simply to invoke the rollback 1515 // rule. 1516 + "%%low-order:\n" 1517 // this rule is only called when there are other characters before. 1518 // It places the numeral mark before the last digit 1519 + " \u2033=%%ones=;\n" 1520 // the rule for 10 places the numeral mark before the 10 character 1521 // (because we know it's the last character); the rule for 11 relies 1522 // on %%tens-and-ones to place the numeral mark 1523 + " 10: \u2033<%%tens<; =%%tens-and-ones=>%%null>;\n" 1524 // the rule for 100 places the numeral mark before the 100 character 1525 // (we know it's the last character); the rule for 101 recurses to 1526 // fill in the remaining digits and the numeral mark 1527 + " 100: <%%hundreds<\u2032; <%%hundreds<>>;\n" 1528 // special-case the hundreds from 500 to 900 because they consist of 1529 // more than one character 1530 + " 500: \u05ea\u2033\u05e7; \u05ea\u05e7>>;\n" 1531 + " 600: \u05ea\u2033\u05e8; \u05ea\u05e8>>;\n" 1532 + " 700: \u05ea\u2033\u05e9; \u05ea\u05e9>>;\n" 1533 + " 800: \u05ea\u2033\u05ea; \u05ea\u05ea>>;\n" 1534 + " 900: \u05ea\u05ea\u2033\u05e7; \u05ea\u05ea\u05e7>>;\n" 1535 // this rule set is used to format values of 1,000 or more. Here, we don't 1536 // worry about the numeral mark, and we add two dots (the Unicode combining 1537 // diaeresis character) to ever letter 1538 + "%%high-order:\n" 1539 // put the ones digit, followed by the diaeresis 1540 + " =%%ones=\u0308;\n" 1541 // the tens can be handled with recursion 1542 + " 10: <%%tens<\u0308[>>];\n" 1543 // still have to special-case 15 and 16 1544 + " 15: \u05d8\u0308\u05d5\u0308; 16: \u05d8\u003078\u05d6\u0308;\n" 1545 // back to the regular rules at 17 1546 + " 17: <%%tens<\u0308[>>];\n" 1547 // the hundreds with the dots added (and without worrying about 1548 // placing the numeral mark) 1549 + " 100: <%%hundreds<\u0308[>>];\n" 1550 + " 500: \u05ea\u0308\u05e7\u0308[>>];\n" 1551 + " 600: \u05ea\u0308\u05e8\u0308[>>];\n" 1552 + " 700: \u05ea\u0308\u05e9\u0308[>>];\n" 1553 + " 800: \u05ea\u0308\u05ea\u0308[>>];\n" 1554 + " 900: \u05ea\u0308\u05ea\u0308\u05e7\u0308[>>];\n" 1555 // this rule set doesn't do anything; it's used by some other rules to 1556 // invoke the rollback rule 1557 + " %%null:\n" 1558 + " ;\n" 1559 // the main rule set. 1560 + "%main:\n" 1561 // for values below 10, just output the letter and the numeral mark 1562 + " =%%ones=\u2032;\n" 1563 // for values from 10 to 99, use %%tens-and-ones to do the formatting 1564 + " 10: =%%tens-and-ones=;\n" 1565 // for values from 100 to 999, use %%low-order to do the formatting 1566 + " 100: =%%low-order=;\n" 1567 // for values of 1,000 and over, use %%high-order to do the formatting 1568 + " 1000: <%%high-order<[>%%low-order>];\n"; 1569 1570 /** 1571 * Greek alphabetic numerals. The Greeks, before adopting the Arabic numerals, 1572 * also used the letters of their alphabet as numerals. There are three now- 1573 * obsolete Greek letters that are used as numerals; many fonts don't have them. 1574 * Large numbers were handled many different ways; the way shown here divides 1575 * large numbers into groups of four letters (factors of 10,000), and separates 1576 * the groups with the capital letter mu (for myriad). Capital letters are used 1577 * for values below 10,000; small letters for higher numbers (to make the capital 1578 * mu stand out). 1579 */ 1580 public static final String greekAlphabetic = 1581 // this rule set is used for formatting numbers below 10,000. It uses 1582 // capital letters. 1583 "%%low-order:\n" 1584 + " (no zero); \u0391; \u0392; \u0393; \u0394; \u0395; \u03dc; \u0396; \u0397; \u0398;\n" 1585 + " 10: \u0399[>>]; 20: \u039a[>>]; 30: \u039b[>>]; 40: \u039c[>>]; 50: \u039d[>>];\n" 1586 + " 60: \u039e[>>]; 70: \u039f[>>]; 80: \u03a0[>>]; 90: \u03de[>>];\n" 1587 + " 100: \u03a1[>>]; 200: \u03a3[>>]; 300: \u03a4[>>]; 400: \u03a5[>>];\n" 1588 + " 500: \u03a6[>>]; 600: \u03a7[>>]; 700: \u03a8[>>]; 800: \u03a9[>>];\n" 1589 + " 900: \u03e0[>>];\n" 1590 // the thousands are represented by the same numbers as the ones, but 1591 // with a comma-like mark added to their left shoulder 1592 + " 1000: \u0391\u0313[>>]; 2000: \u0392\u0313[>>]; 3000: \u0393\u0313[>>];\n" 1593 + " 4000: \u0394\u0313[>>]; 5000: \u0395\u0313[>>]; 6000: \u03dc\u0313[>>];\n" 1594 + " 7000: \u0396\u0313[>>]; 8000: \u0397\u0313[>>]; 9000: \u0398\u0313[>>];\n" 1595 // this rule set is the same as above, but uses lowercase letters. It is used 1596 // for formatting the groups in numbers above 10,000. 1597 + "%%high-order:\n" 1598 + " (no zero); \u03b1; \u03b2; \u03b3; \u03b4; \u03b5; \u03dc; \u03b6; \u03b7; \u03b8;\n" 1599 + " 10: \u03b9[>>]; 20: \u03ba[>>]; 30: \u03bb[>>]; 40: \u03bc[>>]; 50: \u03bd[>>];\n" 1600 + " 60: \u03be[>>]; 70: \u03bf[>>]; 80: \u03c0[>>]; 90: \u03de[>>];\n" 1601 + " 100: \u03c1[>>]; 200: \u03c3[>>]; 300: \u03c4[>>]; 400: \u03c5[>>];\n" 1602 + " 500: \u03c6[>>]; 600: \u03c7[>>]; 700: \u03c8[>>]; 800: \u03c9[>>];\n" 1603 + " 900: \u03c0[>>];\n" 1604 + " 1000: \u03b1\u0313[>>]; 2000: \u03b2\u0313[>>]; 3000: \u03b3\u0313[>>];\n" 1605 + " 4000: \u03b4\u0313[>>]; 5000: \u03b5\u0313[>>]; 6000: \u03dc\u0313[>>];\n" 1606 + " 7000: \u03b6\u0313[>>]; 8000: \u03b7\u0313[>>]; 9000: \u03b8\u0313[>>];\n" 1607 // the main rule set 1608 + "%main:\n" 1609 // for values below 10,000, just use %%low-order 1610 + " =%%low-order=;\n" 1611 // for values above 10,000, split into two groups of four digits 1612 // and format each with %%high-order (putting an M in betwen) 1613 + " 10,000: <%%high-order<\u039c>%%high-order>;\n" 1614 // for values above 100,000,000, add another group onto the front 1615 // and another M 1616 + " 100,000,000: <%%high-order<\u039c>>\n"; 1617 1618 /** 1619 * A list of all the sample rule sets, used by the demo program. 1620 */ 1621 public static final String[] sampleRuleSets = 1622 { usEnglish, 1623 ukEnglish, 1624 spanish, 1625 french, 1626 swissFrench, 1627 german, 1628 italian, 1629 swedish, 1630 dutch, 1631 japanese, 1632 greek, 1633 russian, 1634 hebrew, 1635 ordinal, 1636 message1, 1637 dollarsAndCents, 1638 decimalAsFraction, 1639 closestFraction, 1640 stock, 1641 abbEnglish, 1642 units, 1643 message2, 1644 dozens, 1645 durationInSeconds, 1646 durationInHours, 1647 poundsShillingsAndPence, 1648 arabicNumerals, 1649 wordsForDigits, 1650 chinesePlaceValue, 1651 romanNumerals, 1652 hebrewAlphabetic, 1653 greekAlphabetic }; 1654 1655 /** 1656 * The displayable names for all the sample rule sets, in the same order as 1657 * the preceding array. 1658 */ 1659 public static final String[] sampleRuleSetNames = 1660 { "English (US)", 1661 "English (UK)", 1662 "Spanish", 1663 "French (France)", 1664 "French (Switzerland)", 1665 "German", 1666 "Italian", 1667 "Swedish", 1668 "Dutch", 1669 "Japanese", 1670 "Greek", 1671 "Russian", 1672 "Hebrew", 1673 "English ordinal abbreviations", 1674 "Simple message formatting", 1675 "Dollars and cents", 1676 "Decimals as fractions", 1677 "Closest fraction", 1678 "Stock prices", 1679 "Abbreviated US English", 1680 "Changing dimensions", 1681 "Complex message formatting", 1682 "Dozens", 1683 "Duration (value in seconds)", 1684 "Duration (value in hours)", 1685 "Pounds, shillings, and pence", 1686 "Arabic numerals", 1687 "Words for digits", 1688 "Chinese place-value notation", 1689 "Roman numerals", 1690 "Hebrew ahlphabetic numerals", 1691 "Greek alphabetic numerals" }; 1692 1693 /** 1694 * The base locale for each of the sample rule sets. The locale is used to 1695 * determine DecimalFormat behavior, lenient-parse behavior, and text-display 1696 * selection (we have a hack in here to allow display of non-Latin scripts). 1697 * Null means the locale setting is irrelevant and the default can be used. 1698 */ 1699 public static final Locale[] sampleRuleSetLocales = 1700 { Locale.US, 1701 Locale.UK, 1702 new Locale("es", "", ""), 1703 Locale.FRANCE, 1704 new Locale("fr", "CH", ""), 1705 Locale.GERMAN, 1706 Locale.ITALIAN, 1707 new Locale("sv", "", ""), 1708 new Locale("nl", "", ""), 1709 Locale.JAPANESE, 1710 new Locale("el", "", ""), 1711 new Locale("ru", "", ""), 1712 new Locale("iw", "", ""), 1713 Locale.ENGLISH, 1714 Locale.ENGLISH, 1715 Locale.US, 1716 Locale.ENGLISH, 1717 null, 1718 null, 1719 Locale.ENGLISH, 1720 null, 1721 Locale.ENGLISH, 1722 Locale.ENGLISH, 1723 null, 1724 null, 1725 Locale.UK, 1726 null, 1727 Locale.ENGLISH, 1728 new Locale("zh", "", ""), 1729 null, 1730 new Locale("iw", "", ""), 1731 new Locale("el", "", ""), 1732 null }; 1733 1734 public static final String[] sampleRuleSetCommentary = { 1735 "This demonstration version of the " 1736 + "U.S. English spellout rules has four variants: 1) %simplified is a " 1737 + "set of rules showing the simple method of spelling out numbers in " 1738 + "English: 289 is formatted as \"two hundred eighty-nine\". 2) %alt-teens " 1739 + "is the same as %simplified, except that values between 1,000 and 9,999 " 1740 + "whose hundreds place isn't zero are formatted in hundreds. For example, " 1741 + "1,983 is formatted as \"nineteen hundred eighty-three,\" and 2,183 is " 1742 + "formatted as \"twenty-one hundred eighty-three,\" but 2,083 is still " 1743 + "formatted as \"two thousand eighty-three.\" 3) %ordinal formats the " 1744 + "values as ordinal numbers in English (e.g., 289 is \"two hundred eighty-" 1745 + "ninth\"). 4) %default uses a more complicated algorithm to format " 1746 + "numbers in a more natural way: 289 is formatted as \"two hundred AND " 1747 + "eighty-nine\" and commas are inserted between the thousands groups for " 1748 + "values above 100,000.", 1749 1750 "U.K. English has one significant " 1751 + "difference from U.S. English: the names for values of 1,000,000,000 " 1752 + "and higher. In American English, each successive \"-illion\" is 1,000 " 1753 + "times greater than the preceding one: 1,000,000,000 is \"one billion\" " 1754 + "and 1,000,000,000,000 is \"one trillion.\" In British English, each " 1755 + "successive \"-illion\" is one million times greater than the one before: " 1756 + "\"one billion\" is 1,000,000,000,000 (or what Americans would call a " 1757 + "\"trillion\"), and \"one trillion\" is 1,000,000,000,000,000,000. " 1758 + "1,000,000,000 in British English is \"one thousand million.\" (This " 1759 + "value is sometimes called a \"milliard,\" but this word seems to have " 1760 + "fallen into disuse.)", 1761 1762 "The Spanish rules are quite similar to " 1763 + "the English rules, but there are some important differences: " 1764 + "First, we have to provide separate rules for most of the twenties " 1765 + "because the ones digit frequently picks up an accent mark that it " 1766 + "doesn't have when standing alone. Second, each multiple of 100 has " 1767 + "to be specified separately because the multiplier on 100 very often " 1768 + "changes form in the contraction: 500 is \"quinientos,\" not " 1769 + "\"cincocientos.\" In addition, the word for 100 is \"cien\" when " 1770 + "standing alone, but changes to \"ciento\" when followed by more digits. " 1771 + "There also some other differences.", 1772 1773 "French adds some interesting quirks of its " 1774 + "own: 1) The word \"et\" is interposed between the tens and ones digits, " 1775 + "but only if the ones digit if 1: 20 is \"vingt,\" and 2 is \"vingt-deux,\" " 1776 + "but 21 is \"vingt-et-un.\" 2) There are no words for 70, 80, or 90. " 1777 + "\"quatre-vingts\" (\"four twenties\") is used for 80, and values proceed " 1778 + "by score from 60 to 99 (e.g., 73 is \"soixante-treize\" [\"sixty-thirteen\"]). " 1779 + "Numbers from 1,100 to 1,199 are rendered as hundreds rather than " 1780 + "thousands: 1,100 is \"onze cents\" (\"eleven hundred\"), rather than " 1781 + "\"mille cent\" (\"one thousand one hundred\")", 1782 1783 "Swiss French differs from French French " 1784 + "in that it does have words for 70, 80, and 90. This rule set shows them, " 1785 + "and is simpler as a result.", 1786 1787 "German also adds some interesting " 1788 + "characteristics. For values below 1,000,000, numbers are customarily " 1789 + "written out as a single word. And the ones digit PRECEDES the tens " 1790 + "digit (e.g., 23 is \"dreiundzwanzig,\" not \"zwanzigunddrei\").", 1791 1792 "Like German, most Italian numbers are " 1793 + "written as single words. What makes these rules complicated is the rule " 1794 + "that says that when a word ending in a vowel and a word beginning with " 1795 + "a vowel are combined into a compound, the vowel is dropped from the " 1796 + "end of the first word: 180 is \"centottanta,\" not \"centoottanta.\" " 1797 + "The complexity of this rule set is to produce this behavior.", 1798 1799 "Spellout rules for Swedish.", 1800 1801 "Spellout rules for Dutch. Notice that in Dutch, as in German," 1802 + "the ones digit precedes the tens digit.", 1803 1804 "In Japanese, there really isn't any " 1805 + "distinction between a number written out in digits and a number " 1806 + "written out in words: the ideographic characters are both digits " 1807 + "and words. This rule set provides two variants: %traditional " 1808 + "uses the traditional CJK numerals (which are also used in China " 1809 + "and Korea). %financial uses alternate ideographs for many numbers " 1810 + "that are harder to alter than the traditional numerals (one could " 1811 + "fairly easily change a one to " 1812 + "a three just by adding two strokes, for example). This is also done in " 1813 + "the other countries using Chinese idographs, but different ideographs " 1814 + "are used in those places.", 1815 1816 "Again in Greek we have to supply the words " 1817 + "for the multiples of 100 because they can't be derived algorithmically. " 1818 + "Also, the tens dgit changes form when followed by a ones digit: an " 1819 + "accent mark disappears from the tens digit and moves to the ones digit. " 1820 + "Therefore, instead of using the [] notation, we actually have to use " 1821 + "two separate rules for each multiple of 10 to show the two forms of " 1822 + "the word.", 1823 1824 "Spellout rules for Russian.", 1825 1826 "Spellout rules for Hebrew. Hebrew actually has inflected forms for " 1827 + "most of the lower-order numbers. The masculine forms are shown " 1828 + "here.", 1829 1830 "This rule set adds an English ordinal abbreviation to the end of a " 1831 + "number. For example, 2 is formatted as \"2nd\". Parsing doesn't work with " 1832 + "this rule set. To parse, use DecimalFormat on the numeral.", 1833 1834 "This is a simple message-formatting example. Normally one would " 1835 + "use ChoiceFormat and MessageFormat to do something this simple, " 1836 + "but this shows it could be done with RuleBasedNumberFormat too. " 1837 + "A message-formatting example that might work better with " 1838 + "RuleBasedNumberFormat appears later.", 1839 1840 "The next few examples demonstrate fraction handling. " 1841 + "This example formats a number in one of the two styles often used " 1842 + "on checks. %dollars-and-hundredths formats cents as hundredths of " 1843 + "a dollar (23.40 comes out as \"twenty-three and 40/100 dollars\"). " 1844 + "%dollars-and-cents formats in dollars and cents (23.40 comes out as " 1845 + "\"twenty-three dollars and forty cents\")", 1846 1847 "This rule set shows the fractional part of the number as a fraction " 1848 + "with a power of 10 as the denominator. Some languages don't spell " 1849 + "out the fractional part of a number as \"point one two three,\" but " 1850 + "always render it as a fraction. If we still want to treat the fractional " 1851 + "part of the number as a decimal, then the fraction's denominator " 1852 + "is always a power of 10. This example does that: 23.125 is formatted " 1853 + "as \"twenty-three and one hundred twenty-five thousandths\" (as opposed " 1854 + "to \"twenty-three point one two five\" or \"twenty-three and one eighth\").", 1855 1856 "Number with closest fraction. This example formats a value using " 1857 + "numerals, but shows the fractional part as a ratio (fraction) rather " 1858 + "than a decimal. The fraction always has a denominator between 2 and 10.", 1859 1860 "American stock-price formatting. Non-integral stock prices are still " 1861 + "generally shown in eighths or sixteenths of dollars instead of dollars " 1862 + "and cents. This example formats stock prices in this way if possible, " 1863 + "and in dollars and cents if not.", 1864 1865 "The next few examples demonstrate using a RuleBasedNumberFormat to " 1866 + "change the units a value is denominated in depending on its magnitude. " 1867 + "The example shows large numbers the way they often appear is nwespapers: " 1868 + "1,200,000 is formatted as \"1.2 million\".", 1869 1870 "This example takes a number of meters and formats it in whatever unit " 1871 + "will produce a number with from one to three digits before the decimal " 1872 + "point. For example, 230,000 is formatted as \"230 km\".", 1873 1874 "A more complicated message-formatting example. Here, in addition to " 1875 + "handling the singular and plural versions of the word, the value is " 1876 + "denominated in bytes, kilobytes, or megabytes depending on its magnitude. " 1877 + "Also notice that it correctly treats a kilobyte as 1,024 bytes (not 1,000), " 1878 + "and a megabyte as 1,024 kilobytes (not 1,000).", 1879 1880 "This example formats a number in dozens and gross. This is intended to " 1881 + "demonstrate how this rule set can be used to format numbers in systems " 1882 + "other than base 10. The \"/12\" after the rules' base values controls this. " 1883 + "Also notice that the base doesn't have to be consistent throughout the " 1884 + "whole rule set: we go back to base 10 for values over 1,000.", 1885 1886 "The next few examples show how a single value can be divided up into major " 1887 + "and minor units that don't relate to each other by a factor of 10. " 1888 + "This example formats a number of seconds in sexagesimal notation " 1889 + "(i.e., hours, minutes, and seconds). %with-words formats it with " 1890 + "words (3740 is \"1 hour, 2 minutes, 20 seconds\") and %in-numerals " 1891 + "formats it entirely in numerals (3740 is \"1:02:20\").", 1892 1893 "This example formats a number of hours in sexagesimal notation (i.e., " 1894 + "hours, minutes, and seconds). %with-words formats the value using " 1895 + "words for the units, and %in-numerals formats the value using only " 1896 + "numerals.", 1897 1898 "This rule set formats a number of pounds as pounds, shillings, and " 1899 + "pence in the old English system of currency.", 1900 1901 "These examples show how RuleBasedNumberFormat can be used to format " 1902 + "numbers using non-positional numeration systems. " 1903 + "This example formats numbers in Arabic numerals. " 1904 + "Normally, you'd do this with DecimalFormat, but this shows that " 1905 + "RuleBasedNumberFormat can handle it too.", 1906 1907 "This example follows the same pattern as the Arabic-numerals " 1908 + "example, but uses words for the various digits (e.g., 123 comes " 1909 + "out as \"one two three\").", 1910 1911 "This example formats numbers using Chinese characters in the Arabic " 1912 + "place-value method. This was used historically in China for a while.", 1913 1914 "Roman numerals. This example has two variants: %modern shows how large " 1915 + "numbers are usually handled today; %historical ses the older symbols for " 1916 + "thousands. Not all of the characters are displayable with most fonts.", 1917 1918 "Hebrew alphabetic numerals. Before adoption of Arabic numerals, Hebrew speakers " 1919 + "used the letter of their alphabet as numerals. The first nine letters of " 1920 + "the alphabet repesented the values from 1 to 9, the second nine letters the " 1921 + "multiples of 10, and the remaining letters the multiples of 100. Since they " 1922 + "ran out of letters at 400, the remaining multiples of 100 were represented " 1923 + "using combinations of the existing letters for the hundreds. Numbers were " 1924 + "distinguished from words in a number of different ways: the way shown here " 1925 + "uses a single mark after a number consisting of one letter, and a double " 1926 + "mark between the last two letters of a number consisting of two or more " 1927 + "letters. Two dots over a letter multiplied its value by 1,000. Also, since " 1928 + "the letter for 10 is the first letter of God's name and the letters for 5 and 6 " 1929 + "are letters in God's name, which wasn't supposed to be written or spoken, 15 and " 1930 + "16 were usually written as 9 + 6 and 9 + 7 instead of 10 + 5 and 10 + 6.", 1931 1932 "Greek alphabetic numerals. The Greeks, before adopting the Arabic numerals, " 1933 + "also used the letters of their alphabet as numerals. There are three now-" 1934 + "obsolete Greek letters that are used as numerals; many fonts don't have them. " 1935 + "Large numbers were handled many different ways; the way shown here divides " 1936 + "large numbers into groups of four letters (factors of 10,000), and separates " 1937 + "the groups with the capital letter mu (for myriad). Capital letters are used " 1938 + "for values below 10,000; small letters for higher numbers (to make the capital " 1939 + "mu stand out).", 1940 1941 "This is a custom (user-defined) rule set." 1942 }; 1943 } 1944