It does fix the issue temporarily but later in the code these variables show value of 11 digit decimal places again. This happens when they are used for calculation. How can I restrict the decimal paces permanently to 2 digits only such that no matter what happens in the code it does not show more than 2 digits. openCurrentBar should be something like 2365.21 and NOT 2365.213456721309.
would that permanently restrict the decimal places to 2 places. What if this variable is reassigned a values later on in code. Would it again change back to 10 digits or so?
//initiallytrailingAmount=priceAtBuy * 0.5/100;//later in the code WILL THIS AGAIN SET IT BACK TO 12 DIGITS ?? trailingAmount=priceAtBuy * trailingPercentage/100;
If you go by my third and fourth sentences, that question becomes academic
PearlJamFanatic
ASKER
CEHG so what you suggest is that I use the values with all the decimals for my calculation and only at the time of display I use a rounding function like the one I am using now. Is that right? will this not make debugging rather difficult? I need to think about this. I use this code to create labels for display on the chart.
so what you suggest is that I use the values with all the decimals for my calculation and only at the time of display I use a rounding function like the one I am using now. Is that right?
Actually that's a 'yes' with the qualification that you haven't restricted the actual value's precision at all. Only what the user sees
PearlJamFanatic
ASKER
Ok I have made the changes in my code. I use the Util.round() at the time of display. Why do you suggest converting to string for display? why not use the SDK provided function like Util.round() which takes double and returns double. Why should it matter as it is only for display?
CEHJ
Because strings are more predictable. And there's less likelihood of using the imprecise value in further calculations
Open in new window