Do somthings

In this Article, we understand how to convert integer to word with the help of JAVA. first, you understand what is Integer.  Integers are whole numbers, for example, -35, 0, 2048, …. Integers are represented in binary inside the computer, and in decimal in Java source programs. Java automatically converts decimal numbers you write in your source program into binary numbers internally.

in this project, we are Using one dependency  “icu4J” which is converted from an integer to a word. 

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio click File->New->New Project in Android Studio. Note: select Java as the programming language.

Step 2: Add the below dependency to your build.Gradle file.

//integer to word Dependency

implementation group: ‘com.ibm.icu’, name: ‘icu4j’, version: ‘51.1’

After adding this dependency please sync your project and now move towards the MainActivity file.

Step 3: Working with the MainActivity.java file

Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.

package com.example.integertoword;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.ibm.icu.text.RuleBasedNumberFormat;

import java.util.Locale;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

double value = 56;

//call here to funtion...
String english=convertIntoWords(value,"en","US"); //convert to the english word
System.out.println(english);




}

//create a function integerToWordConverter...

private String convertIntoWords(Double str,String language,String Country) {
Locale local = new Locale(language, Country);
RuleBasedNumberFormat ruleBasedNumberFormat = new RuleBasedNumberFormat(local, RuleBasedNumberFormat.SPELLOUT);
return ruleBasedNumberFormat.format(str);
}
}

Now run your app and see the output of the app.

OutPut:

Categories: JAVA

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *