/* * [Indonesian.java] * * Summary: Displays numbers in Bahasa Indonesia (Indonesian). * * Copyright: (c) 1999-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 1999-01-13 * 1.1 1999-01-14 add proper words for billion, trillion etc. * 1.2 1999-01-21 make all language specific String literals into constants. */ package com.mindprod.inwords; /** * Displays numbers in Bahasa Indonesia (Indonesian). *

* e.g. * -12345 -> "minus duabelas ribu tiga ratus empatpuluh * lima". * This needs to be verified by an Indonesian speaker, especially for large numbers. *

* * @author Roedy Green, Canadian Mind Products * @version 1.2 1999-01-21 make all language specific String literals into constants. * ased in information the Berlitz Indonesian Phrase Book and Dictionary * ISBN: 2-8315-0932-7) * hanks also to: Iskandar Baharuddin <brengsek@highway1.com.au> * or information on large numbers. * ndonesian counting is similar to English, but a little simpler, since * he numbers for 20, 30 .. 90 are regular. It is like Norwegian in * aving special * form for one before 100 or 1000. * @ Based in information the Berlitz Indonesian Phrase Book and Dictionary * (ISBN: 2-8315-0932-7) * Thanks also to: Iskandar Baharuddin <brengsek@highway1.com.au> * for information on large numbers. *

* Indonesian counting is similar to English, but a little simpler, since * the numbers for 20, 30 .. 90 are regular. It is like Norwegian in * having special form for one before 100 or 1000. *

* Why is this code written in an unusual way? see inwords.use * @since 1999-01-13 */ public final class Indonesian implements ToWords { private static final int FIRST_COPYRIGHT_YEAR = 1999; /** * undisplayed copyright notice * * @noinspection UnusedDeclaration */ private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 1999-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; private static final String MINUS = "minus"; /* twenty thirty etc are regular, just add this suffix */ private static final String TY = "puluh"; private static final String ZERO = "nol"; private static final String[] groupName = { /* * American: unit, hundred, thousand, million, billion, trillion, * quadrillion, quintillion */ "", "ratus", "ribu", "juta", "milyar", "trilyun", "kwadrilyun", "kwintilyun" }; private static final String[] lowName = { /* names of digits 0..19 */ /* zero is shown as "" since is "nol" is not used in combinations */ "", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas", "duabelas", "tigabelas", "empatbelas", "limabelas", "enambelas", "tujuhbelas", "delapanbelas", "sembilanbelas" }; private static final String[] ONE = { "satu", "se" }; private static final int[] divisor = { /* * how many of this group is needed to form one of the succeeding group. */ /* * American: unit, hundred, thousand, million, billion, trillion, * quadrillion, quintillion */ 100, 10, 1000, 1000, 1000, 1000, 1000, 1000 }; /** * test harness * * @param args not used */ public static void main( String[] args ) { Test.test( new Indonesian() ); } // end main /** * convert long integer into Indonesian words e.g. -12345 -> "minus duabelas ribu tiga ratus empatpuluh lima". * Handles negative and positive integers on range -Long.MAX_VALUE .. Long.MAX_VALUE; It cannot handle * Long.MIN_VALUE; * * @param num number to convert to words * * @return words */ @SuppressWarnings( { "WeakerAccess" } ) public String toWords( long num ) { if ( num == 0 ) { return ZERO; } boolean negative = ( num < 0 ); if ( negative ) { num = -num; } String s = ""; // Work least significant digit to most, right to left. // until high order part is all 0s. for ( int group = 0; num > 0; group++ ) { int remdr = ( int ) ( num % divisor[ group ] ); num = num / divisor[ group ]; if ( remdr == 0 ) { continue; } String t; if ( remdr == 1 ) { if ( group == 1 || group == 2 ) { t = ONE[ 1 ];// prefix combining form for one before 100 // and 1000 } else { t = ONE[ 0 ] + " ";// usual form } } else if ( remdr < 20 ) { t = lowName[ remdr ] + " "; } else if ( remdr < 100 ) { int units = remdr % 10; int tens = remdr / 10; t = lowName[ tens ] + TY + " "; if ( units != 0 ) { t += lowName[ units ] + " "; } } else { t = toWords( remdr ) + " "; } s = t + groupName[ group ] + " " + s; } // end for s = s.trim(); if ( negative ) { s = MINUS + " " + s; } return s; } // end inWords } // end Indonesian