How to add float variables

Posted on 2006-11-07
Last Modified: 2010-03-31
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.

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.
Question by:aswam1975
  • 4
LVL 86

Expert Comment

ID: 17893049
float total = 0.0;

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

Accepted Solution

CEHJ earned 35 total points
ID: 17893053

float total = 0.0f;

Author Comment

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

Expert Comment

ID: 17893098
No problem
LVL 86

Expert Comment

ID: 17893118

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 53
egit plugin on eclipse 8 82
login jsp example 24 69
eclipse apache tomcat admin console 52 124
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

821 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