Groups
Sign in
Groups
日本Androidの会
Conversations
About
Send feedback
Help
リソースでfloatを扱いたい
829 views
Skip to first unread message
KiyoKiyo
unread,
Feb 16, 2012, 9:36:54 AM
2/16/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 日本Androidの会
件名のとおりです。
0.5などの値をリソースに定義して取得することは可能でしょうか?
"0.5"などの文字列型としてリソースに定義しておいて
float value =
Integer.parseFloat(getResources.getString(R.string.valueA));
で取得することでなんとかしのいでいますが、
もっとスマートにfloatを定義できないもんでしょうか?
よろしくお願いします。
bina
unread,
Feb 16, 2012, 12:29:07 PM
2/16/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 日本Androidの会
binaです。
検索してみると、下記の方法があるようです。
<dimen name="value">0.5px</dimen>
getResources().getDimension(R.dimen.value);
試してみたところ0.5は取得できましたが、
0.3と定義すると誤差が出てしまいました。
参考になれば幸いです。
W少年
unread,
Mar 4, 2012, 8:00:17 AM
3/4/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 日本Androidの会
BigDecimalの魔術師のW少年です。
通常の実数型は2進数なので小数は誤差がどうしても避けられません。値を取得することができたらString型として取得してnew
BigDecimal(String s)というメソッドを使います。BigDecimalの基本パッケージはAndroid環境上でも用意されており
テイラー展開を応用すれば数学関数の計算も可能です。なお、BigDecimalの計算ライブラリは私のホームページで公開しておりますのでご希望であ
ればご返信ください。
Reply all
Reply to author
Forward
0 new messages