# Decimal Point

Page 1 of 1

## 4 Replies - 1888 Views - Last Post: 04 November 2008 - 05:17 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=64747&amp;s=2e106752907f332d8e8ca3cc58a6b420&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 didi2005

Reputation: 0
• Posts: 36
• Joined: 15-September 08

# Decimal Point

Posted 22 September 2008 - 07:13 PM

```
import java.io.*;
import java.text.DecimalFormat;

public class Q1a {
public static void main (String args[]) throws IOException

{

float loan_amount, interest_rate, interest, principal, unpaid_amount, installment;
float total_interest = 0;
int loan_period, loan_period_month;
int payment_no = 0;
int a;

System.out.print("Enter loan amount (RM):"); //Input of loan amount
System.out.println("Loan amount is "+loan_amount);

System.out.print("Enter annual interest rate(%):"); //Input of interest rate
System.out.println("Interest rate is "+interest_rate);

System.out.print("Enter loan period(year):"); //Input of loan period
loan_period_month = loan_period * 12;
System.out.println("Loan period is " +loan_period_month+ " months");

System.out.print("Enter monthly installment amount:"); //Input of monthly payment
System.out.println("Monthly installment is RM" +installment);

System.out.println(""); //spacing

System.out.println(""); //spacing

DecimalFormat twoDigits = new DecimalFormat(".00");
System.out.println("Payment\t\t\t\t\tUnpaid\t\tTotal Interest"); //Output of table listing
System.out.println("No.\tInterest\tPrincipal\tBalance\t\tTo Date\t");

for ( a = 1; a <= loan_period_month; a++){
payment_no++;
interest = loan_amount * loan_period_month / 100 / 12;
principal = installment - interest;
unpaid_amount = loan_amount - principal;
total_interest += interest;
System.out.println("" + payment_no + "\t" + interest + "\t\t" + principal + "\t\t" + unpaid_amount + "\t\t" + total_interest);
loan_amount = unpaid_amount;

}

}
}

```

This is the outcome of my program.

How do i make the table values 2 decimal point only? Example, 41.96.
I've tried using "import java.text.DecimalFormat;" and "DecimalFormat twoDigits = new DecimalFormat("\$##,###.##");" in my coding...

Is This A Good Question/Topic? 0

## Replies To: Decimal Point

### #2 pbl

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

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

## Re: Decimal Point

Posted 22 September 2008 - 07:26 PM

nice to have created your DecimalFormat but you'll have to use it

```		System.out.println("" + payment_no
+ "\t" + twoDigits.format(interest) + "\t\t"
+ twoDigits.format(principal)
+ "\t\t" + twoDigits.format(unpaid_amount)
+ "\t\t" + twoDigits.format(total_interest));

```

### #3 didi2005

Reputation: 0
• Posts: 36
• Joined: 15-September 08

## Re: Decimal Point

Posted 22 September 2008 - 08:01 PM

pbl, on 22 Sep, 2008 - 07:26 PM, said:

nice to have created your DecimalFormat but you'll have to use it

```		System.out.println("" + payment_no
+ "\t" + twoDigits.format(interest) + "\t\t"
+ twoDigits.format(principal)
+ "\t\t" + twoDigits.format(unpaid_amount)
+ "\t\t" + twoDigits.format(total_interest));

```

Thx for your help, now i able to use it.

### #4 ida200

Reputation: 0
• Posts: 1
• Joined: 04-November 08

## Re: Decimal Point

Posted 04 November 2008 - 12:50 AM

why in this program i try the read statement cannot fine. the syntax is symbol cannot resolve

### #5 pbl

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

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

## Re: Decimal Point

Posted 04 November 2008 - 05:17 PM

ida200, on 3 Nov, 2008 - 11:50 PM, said:

why in this program i try the read statement cannot fine. the syntax is symbol cannot resolve

From Sept 22nd to today... what is the exact question ?
You have an error ?
Compile error ? What it is ?
Run time error ? What it is ?