Issue
One of the requirements of my code is that an alpha value is used. I want to program my application so that at some point in the future, I can easily change this value.
My understanding is that resources are built specifically for this purpose. Alpha needs to be between 0 and 1.
I wondered if there was a more elegant solution than setting the value to an integer between 1 and 100 in the integer resource folder, then dividing by 100 in the code.
Current code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- choose a value for alpha, it will be divided by 100.
valid values lie between 0 and 100.-->
<item name = "exponential_filter_alpha" format="">9</item>
</resources>
I saw a similar question here: https://stackoverflow.com/a/8780360/1014849 But that required floats, doubles are not available via that method.
Solution
Based on your comment, I understand your questions as a performance question.
Saving and using an int in resources instead of a float should not be noticeable in the performance at all. By that note I think saving an int and then dividing by 100 all the time would be silly, when you could just as well save a float. Also noting that when you divide your int it will get implicitly converted to a double anyway.
You say that you use the value for an alpha value, and you might only need the precision 1 to 100, using a float for that kind of precision is very reasonable, and also reasonable for an alpha value.
You might want to read Float or Double?
Answered By - Jesper Riemer Andersen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.