Well, maybe I just need a second pair of eyes.
I have a float, I turn into a string. Then I want to break it down into a period / decimal to represent it as a currency.
Here is my code:
float price = new Float("3.76545"); String itemsPrice = "" + price; if (itemsPrice.contains(".")){ String[] breakByDecimal = itemsPrice.split("."); System.out.println(itemsPrice + "||" + breakByDecimal.length); if (breakByDecimal[1].length() > 2){ itemsPrice = breakByDecimal[0] + "." + breakByDecimal[1].substring(0, 2); } else if (breakByDecimal[1].length() == 1){ itemsPrice = breakByDecimal[0] + "." + breakByDecimal[1] + "0"; } }
If you take this and run it, you will get an array index error outside the bounds of line 6 (in the code above) that there is nothing left after the decimal value.
Actually on line 5, when I print the size of the array, it is 0.
These are ridiculous mistakes for them to NOT be what I just ignore.
As I said, another pair of eyes is exactly what I need, so please do not be rude, pointing out what is obvious to you, but I did not pay attention to it.
Thanks in advance!
source share