Kotlin 将比特币价值转换为中本聪价值
Kotlin Convert Bitcoin value into Satoshi Value
//---------------------------------------- --------------------------------------
嗨,这是我的第一个“问题”。我很高兴成为社区的一员。我想获得 Satoshi 硬币的价值(它是 1 BTC 的 100.000.000)我能够找到 1 BTC 的美元价值。基本上,我可以将 1BTC 的美元价值除以 100.000.000 吗?但是如何将值放入 TextView 或 EditText?
//---------------------------------------- --------------------------------------
调试错误。
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.thordalenterprise.satoshiconverter, PID: 19493
java.lang.NumberFormatException: For input string: "45,586"
at java.lang.Integer.parseInt(Integer.java:615)
at java.lang.Integer.parseInt(Integer.java:650)
at com.thordalenterprise.satoshiconverter.MainActivity$loadPrice.onResponse(MainActivity.kt:65)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:929)W/atoshiconverte: Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (greylist, reflection, allowed)V/AudioManager: isWiredHeadsetOn...I/Process: Sending signal. PID: 19493 SIG: 9
//---------------------------------------- --------------------------------------
// Functions
private fun loadPrice() {
val request: Request = Request.Builder().url(BPI_ENDPOINT).build()
val EurView:TextView = findViewById<TextView>(R.id.EURreturn)
val usdView:TextView = findViewById<TextView>(R.id.USDRETURN)
val btcView:TextView = findViewById<TextView>(R.id.BitcoinViewReturner)
val SatoshiC:EditText = findViewById(R.id.SatoshiCount)
val ddx:EditText = findViewById(R.id.editTextNumber)
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call?, e: IOException?) { }
override fun onResponse(call: Call?, response: Response?) {
val json = response?.body()?.string()
val read = Scanner(System.`in`)
// we get the json response returned by the Coin Desk API
// make this call on a browser for example to watch the properties
// here we get USD and EUR rates properties
// we split the value got just to keep the integer part of the values
val btcRate:String = "1"
val SatoshiCoin:Int = 100000000
val usdRate = (JSONObject(json).getJSONObject("bpi").getJSONObject("USD")["rate"] as String).split(".")[0]
val satosh = usdRate.toInt() / 100000000
val num = 2.toBigDecimal().divide(2.toBigDecimal()).toInt()
//Problem start
val satoshiValue = usdRate.toInt() / SatoshiC.text.toString().toInt() * satosh
btcView.text = satoshiValue.toChar().toString()
//Problem end
java.lang.NumberFormatException:对于输入字符串:“45,586”
表示您的字符串包含 , 您应该删除,正确格式化字符串。
示例 45,586 相反,您应该将 45586 作为字符串传递
//---------------------------------------- --------------------------------------
嗨,这是我的第一个“问题”。我很高兴成为社区的一员。我想获得 Satoshi 硬币的价值(它是 1 BTC 的 100.000.000)我能够找到 1 BTC 的美元价值。基本上,我可以将 1BTC 的美元价值除以 100.000.000 吗?但是如何将值放入 TextView 或 EditText?
//---------------------------------------- --------------------------------------
调试错误。
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.thordalenterprise.satoshiconverter, PID: 19493
java.lang.NumberFormatException: For input string: "45,586"
at java.lang.Integer.parseInt(Integer.java:615)
at java.lang.Integer.parseInt(Integer.java:650)
at com.thordalenterprise.satoshiconverter.MainActivity$loadPrice.onResponse(MainActivity.kt:65)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:929)W/atoshiconverte: Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (greylist, reflection, allowed)V/AudioManager: isWiredHeadsetOn...I/Process: Sending signal. PID: 19493 SIG: 9
//---------------------------------------- --------------------------------------
// Functions
private fun loadPrice() {
val request: Request = Request.Builder().url(BPI_ENDPOINT).build()
val EurView:TextView = findViewById<TextView>(R.id.EURreturn)
val usdView:TextView = findViewById<TextView>(R.id.USDRETURN)
val btcView:TextView = findViewById<TextView>(R.id.BitcoinViewReturner)
val SatoshiC:EditText = findViewById(R.id.SatoshiCount)
val ddx:EditText = findViewById(R.id.editTextNumber)
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call?, e: IOException?) { }
override fun onResponse(call: Call?, response: Response?) {
val json = response?.body()?.string()
val read = Scanner(System.`in`)
// we get the json response returned by the Coin Desk API
// make this call on a browser for example to watch the properties
// here we get USD and EUR rates properties
// we split the value got just to keep the integer part of the values
val btcRate:String = "1"
val SatoshiCoin:Int = 100000000
val usdRate = (JSONObject(json).getJSONObject("bpi").getJSONObject("USD")["rate"] as String).split(".")[0]
val satosh = usdRate.toInt() / 100000000
val num = 2.toBigDecimal().divide(2.toBigDecimal()).toInt()
//Problem start
val satoshiValue = usdRate.toInt() / SatoshiC.text.toString().toInt() * satosh
btcView.text = satoshiValue.toChar().toString()
//Problem end
java.lang.NumberFormatException:对于输入字符串:“45,586”
表示您的字符串包含 , 您应该删除,正确格式化字符串。
示例 45,586 相反,您应该将 45586 作为字符串传递