Solved

How to add float variables

Posted on 2006-11-07
5
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 67
jboss wildfly 10.1 10 630
sql import cannot be resolved jsp 3 117
ejb mdb examples 1 39
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

752 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