# Number Manipulation

Page 1 of 1

## 8 Replies - 1551 Views - Last Post: 20 August 2010 - 01:31 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=184779&amp;s=2268783ebc39f16444f8760b559c4eea&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 virs6

Reputation: 0
• Posts: 3
• Joined: 06-August 10

# Number Manipulation

Posted 06 August 2010 - 01:26 AM

This is the problem...say you are given 1/3, the answer for that was 3.3333 and so on and so forth in other words its infinite,,,how are you going to make it that the answer must be 3.(3) instead of an infinite .3?,,thanks for your help....need asap.
Is This A Good Question/Topic? 0

## Replies To: Number Manipulation

### #2 Cuzzie

• D.I.C Regular

Reputation: 72
• Posts: 341
• Joined: 16-July 10

## Re: Number Manipulation

Posted 06 August 2010 - 01:39 AM

First of all, 1/3 = 0.33333, not 3.33333. You mean you want to format the number of decimal places? You'll be needing DecimalFormat.

Example:

```import java.text.DecimalFormat;

public class something{

public static void main(String[] args){

DecimalFormat df = new DecimalFormat("#.##");
double number = 0.333333333;
//formatting the number into two decimal places
System.out.println(df.format(number));

}

}

```

This post has been edited by Cuzzie: 06 August 2010 - 01:40 AM

### #3 pbl

• There is nothing you can't do with a JTable

Reputation: 8365
• Posts: 31,956
• Joined: 06-March 08

## Re: Number Manipulation

Posted 08 August 2010 - 08:11 PM

Cuzzie, on 06 August 2010 - 02:39 AM, said:

First of all, 1/3 = 0.33333, not 3.33333. You mean you want to format the number of decimal places? You'll be needing DecimalFormat.

Example:

```import java.text.DecimalFormat;

public class something{

public static void main(String[] args){

DecimalFormat df = new DecimalFormat("#.##");
double number = 0.333333333;
//formatting the number into two decimal places
System.out.println(df.format(number));

}

}

```

Don't see how a BigDecimal would fix this problem ???
Even if you have a BidDecimal with 5 billions decimal you will still have decimals missing

This post has been edited by pbl: 08 August 2010 - 08:26 PM

### #4 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: Number Manipulation

Posted 08 August 2010 - 08:19 PM

Out of curiosity pbl, why is his answer unacceptable? That is how I would format the number

### #5 pbl

• There is nothing you can't do with a JTable

Reputation: 8365
• Posts: 31,956
• Joined: 06-March 08

## Re: Number Manipulation

Posted 08 August 2010 - 08:23 PM

Luckless, on 08 August 2010 - 09:19 PM, said:

Out of curiosity pbl, why is his answer unacceptable? That is how I would format the number

Sorry my mistake....
I might have been to quick
I saw BigDecimnal instead or DecimalFormat
Please give a +1 to Cuzzie to cancel my -1
My apologies to them

### #6 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: Number Manipulation

Posted 08 August 2010 - 08:26 PM

it's alright, I just didn't want to cancel it out if there was a good reason Keep it up Cuzzie

### #7 pbl

• There is nothing you can't do with a JTable

Reputation: 8365
• Posts: 31,956
• Joined: 06-March 08

## Re: Number Manipulation

Posted 08 August 2010 - 08:28 PM

Luckless, on 08 August 2010 - 09:26 PM, said:

it's alright, I just didn't want to cancel it out if there was a good reason Keep it up Cuzzie

And +1 for you for pointing out this error to me

### #8 Cuzzie

• D.I.C Regular

Reputation: 72
• Posts: 341
• Joined: 16-July 10

## Re: Number Manipulation

Posted 09 August 2010 - 01:00 AM

pbl, on 09 August 2010 - 02:23 AM, said:

Luckless, on 08 August 2010 - 09:19 PM, said:

Out of curiosity pbl, why is his answer unacceptable? That is how I would format the number

Sorry my mistake....
I might have been to quick
I saw BigDecimnal instead or DecimalFormat
Please give a +1 to Cuzzie to cancel my -1
My apologies to them

It's alright.

### #9 virs6

Reputation: 0
• Posts: 3
• Joined: 06-August 10

## Re: Number Manipulation

Posted 20 August 2010 - 01:31 AM

sorry...my mistake...yup its 0.3333,,,