簡體   English   中英

使用字符串數字的更簡單方法?

[英]Simpler way to work with string numbers?

有沒有更簡單的方法可以做到這一點?

int score = Integer.parseInt(tv_score.getText());
score += 100;
tv_score.setText(String.valueOf(score));

是的,有一種更簡單的方法來處理原始對象數據類型,而不是原始數據類型

Integer score = new Integer(tv_score.getText());
score += 100;
tv_score.setText(score.toString());

或者您也可以這樣做,使它更簡短,更精確

Integer score = new Integer(tv_score.getText())+100;
tv_score.setText(score.toString());

int分數= Integer.parseInt(tv_score.getText());

如果我能看到,在文本字段或文本區域中輸入的數字不是十進制格式,則此方法將不起作用。

If the number will always be in decimal format, then use
 - int x = Integer.parseInt("11") + 10;

And for an instance, if the number is in hexadecimal format, then use
- int x = Integer.parseInt("1B", 16) + 10;

希望這會有所幫助。 :-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM