8 Replies - 1087 Views - Last Post: 20 August 2010 - 01:31 AM Rate Topic: -----

#1 virs6  Icon User is offline

  • New D.I.C Head

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

Number Manipulation

Posted 06 August 2010 - 01:26 AM

How am i going to solve this problem???could somebody please help me,,,
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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 72
  • View blog
  • 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

Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

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

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Number Manipulation

Posted 08 August 2010 - 08:11 PM

View PostCuzzie, 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

My bad sorry

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

Was This Post Helpful? 0
  • +
  • -

#4 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • 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
Was This Post Helpful? 1
  • +
  • -

#5 pbl  Icon User is offline

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

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Number Manipulation

Posted 08 August 2010 - 08:23 PM

View PostLuckless, 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
Was This Post Helpful? 0
  • +
  • -

#6 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • 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 :bigsmile: Keep it up Cuzzie
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

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

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Number Manipulation

Posted 08 August 2010 - 08:28 PM

View PostLuckless, 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 :bigsmile: Keep it up Cuzzie

And +1 for you for pointing out this error to me
Was This Post Helpful? 0
  • +
  • -

#8 Cuzzie  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: Number Manipulation

Posted 09 August 2010 - 01:00 AM

View Postpbl, on 09 August 2010 - 02:23 AM, said:

View PostLuckless, 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. :)
Was This Post Helpful? 0
  • +
  • -

#9 virs6  Icon User is offline

  • New D.I.C Head

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

Re: Number Manipulation

Posted 20 August 2010 - 01:31 AM

sorry...my mistake...yup its 0.3333,,,
thanks for your reply,..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1