Code reviewing, came across this:

Double val = item.getPrice() * pointMultiplier;
String[] s = String.split(val.toString(), "\\.");
points = Integer.parseInt(s[0]);
if(Integer.parseInt(s[1]) > 0) { points++; }

Usually I'd leave it at that, but to add insult to injury this was a level 3 developer who had been there for four (4!!!!) years.

She argued with me that we shouldn't round up loyalty points if theres only 0.00001 in the calculation.
I argued that since it's a BigDecimal, we can set the rounding factor of it.
She didn't understand that solution, refused to hear it.

The code is probably still there.

  • 2
    Took me a good minute to understand this was a rounding thing!

    Edit: wait! Does this literally round up 1.000001 to 2
  • 1
    Uhhh since you're working with Double, can't you use the Math class? Or am I missing something here... That just seems very inefficient...
  • 1
    I feel like I need PEMDAS to unscramble some of this.
  • 3
    @-vim- yes - sorry There was one part I was forgetting that I just remembered. They were doing this on the Double:

    String.format("%.02f", val);

    So they were using String.format() to get 2 decimal places rather than using BigDecimal's ability to set a rounding factor <facepalm>

    @nanoandrew4: yes that was my suggestion, Math.ceil() on the BigDecimal after setting the rounding factor to 2. Apparently that's too complicated though <shrug>

    @JohnScott: LOL yes, basically it was this,

    1. Multiply price by point factor (eg 2%)

    2. Convert double amount to string with 2 decimal places

    3. Split String by decimal point, using first element in array as point value, and adding one if the second element in the array isn't 0.

    It was so terrible. The rage was strong. When I fought to get it changed to something a bit more sane like Math.ceil() and she didn't agree is honestly when I lost a lot of respect from an angineering standpoint.
  • 1
    @lindgrenj6 That's very specific. But I understand it now.

    You have my sympathy.
Add Comment