Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

How to add float variables

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
aswam1975
Asked:
aswam1975
  • 4
1 Solution
 
CEHJCommented:
float total = 0.0;

// (inloop)
total += Arr[i].getDiscount()
0
 
CEHJCommented:
Sorry

float total = 0.0f;
0
 
aswam1975Author Commented:
Thanks- I just re tried using primitives and converted the getDiscount to a floatValue and works fine!
0
 
CEHJCommented:
No problem
0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now