Solved

How to add float variables

Posted on 2006-11-07
5
230 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

759 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

24 Experts available now in Live!

Get 1:1 Help Now