Kotlin Convert Bitcoin value into Satoshi Value

0 votes

Hi, this is my very first "ask". I am happy to be a part of the community. I want to obtain the value of a Satoshi coin. I am able to find the value of 1 BTC in USD$. Basically, can I just divide the value of 1BTC in USD$ by 100.000.000? But how can I put the value into a TextView or EditText?

Debug Error.

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$1.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

Apr 6, 2022 in Blockchain by Rahul
• 9,670 points

1 answer to this question.

0 votes
 java.lang.NumberFormatException: For input string: "45,586"

This means your string contains, you should remove, format the string properly.

For example 45,586 instead you should pass 45586 as the string

answered Apr 12, 2022 by Soham
• 9,700 points

Related Questions In Blockchain

0 votes
0 answers

API - Convert Bitcoin Amount into USD with my Api

After apiv2.bitcoinaverage.com is not free anymore I ...READ MORE

Mar 2, 2022 in Blockchain by Aditya
• 7,680 points
0 votes
1 answer

How to get current value of bitcoin?

You can use json_decode to transform it ...READ MORE

answered Aug 20, 2018 in Blockchain by digger
• 26,740 points
0 votes
1 answer

How to convert Bitcoin rate to USD?

You can use blockchain.info API: URL: https://blockchain.info/ticker Response: { "USD" ...READ MORE

answered Aug 21, 2018 in Blockchain by slayer
• 29,350 points
0 votes
1 answer

How to get genesis block value at new bitcoin source?

chainparams.cpp contains a line of code that ...READ MORE

answered Sep 4, 2018 in Blockchain by digger
• 26,740 points
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
0 votes
1 answer

Bitcoin - BitGO - Save all wallet objects into Array of Objects

 After noticing your following code: docs.forEach(function(address) { console.log(address); var ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,700 points
0 votes
1 answer

How can I import a Bitcoin paper wallet key into a bitcoinlib wallet?

Your code should work in the latest ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,700 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP