Solved

How to add float variables

Posted on 2006-11-07
5
235 Views
Last Modified: 2010-03-31
Hi;
I have a method that is of type
public Float get Discount()

I want to keep  a counter that gets all the discount value and if the value is greater than 100 it will flag an aerror.
Hence

Float counter = new Float(0)

for(int i=0;i< Arr.length;i++)
counter = counter + Arr[i].getDiscount()
where Arr[i].getDiscount return type is float.

What is the best way to do this.
0
Comment
Question by:aswam1975
  • 4
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17893049
float total = 0.0;

// (inloop)
total += Arr[i].getDiscount()
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 35 total points
ID: 17893053
Sorry

float total = 0.0f;
0
 

Author Comment

by:aswam1975
ID: 17893081
Thanks- I just re tried using primitives and converted the getDiscount to a floatValue and works fine!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17893098
No problem
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17893118
:-)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

808 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