Method in java to remove decimal from string

Posted on 2009-03-30
Last Modified: 2012-05-06
I am a newbie in java and need a method to remove any decimal from any length string and convert it without decimal. For example:

0.5555 should become 5555
0.045 should become 45
24.67 should become 2467
What is the simplest way to do this.
Question by:rheasam
  • 3
  • 2

Assisted Solution

brunoguimaraes earned 100 total points
ID: 24021846
See if this helps.
private static String removeDecimals(String number) {


		String numberNoDots = number.replace(".", "");

		int index = -1;


		for (int i = 0; i < numberNoDots.length(); i++)

			if (numberNoDots.charAt(i) != '0') {

				index = i;




		return numberNoDots.substring(index);


Open in new window


Author Comment

ID: 24022043
Let me check
LVL 86

Accepted Solution

CEHJ earned 400 total points
ID: 24022288
All you need is the following, where 's' is the input string
s = "" + Integer.parseInt(s.replaceAll("\\.", ""));

Open in new window

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!


Author Comment

ID: 24022514
CEHJ, will that take care of number like 05.05 also and make it 505

LVL 86

Expert Comment

ID: 24023329

Author Comment

ID: 24023719
k, cool. I will award the points by tomorrow

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changePi Challenge 15 76
array11 challenge 16 51
wordmultiple challenge 12 90
Java / Linux and Regular Expressions 11 47
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now