Hello I am making a currency converter, from Indonesian rupiah to 12 other currencies.
In the example below, I would like to obtain:
for 10 RUPIAH ➝ 0.001 eur
for 100 RP ➝ 0.006 eur
for 1000 RP ➝ 0.06 eur
for 100,000 RP ➝ 6 eur
for 1,000,000 RP ➝ 60 eur
for 10,000,000 RP ➝ 600 eur
I made an example of the rupiah to euro. I have a field where I enter a value and the other values automatically update.
My problem is, that in the display tab, it puts values with exponents. I would like to have a number with a maximum of 2 digits after the point. is there a method to get this? Thank you!
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
valeurIdr.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.toString().equals("")) {
resultEuro.text=null
} else {
val idr = valeurIdr?.text.toString().toDouble()
val euro = 0.000060
resultEuro?.setText((idr * euro).toString())
}
}
override fun beforeTextChanged(
s: CharSequence, start: Int, count: Int, after: Int) {
}
override fun afterTextChanged(s: Editable) {
// TODO Auto-generated method stub
}
})
}
}
First of all That is mathematically incorrect.
But IF you wanted to 6.000000 = 6.00
Above method with give you the highet value of 2 digits ex: 1.78345 = 1.79