-
-
Save anonymous/fa134c55a4a43e8d6004 to your computer and use it in GitHub Desktop.
/** | |
* This method displays the given price on the screen. | |
*/ | |
private void displayPrice(int number) { | |
TextView priceTextView = (TextView) findViewById(R.id.price_text_view); | |
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number)); | |
} |
TIP:
The currency used is the one your phone uses, not what is set on your computer. Some phones don't allow you to change the currency explicitly, but your selected language on the phone dictates this, for example choosing English (United Kingdom) will automatically set the currency to "£" (Pounds).
On a Samsung phone in most cases this can be set under Options->Controls->Language and Input
Thnx Buddy!!! It Resolves my problem.
@chekwon78 Do try adding a TextView in activity_main.xml and assign it an id like this
android:id="@+id/price_text_view"
.
Thanks soo much ,it worked for me
It's ok, solved by adding "import java.text.NumberFormat;" . thanks.
don't why my app is crashing after clicking on the ORDER button
Code of [chetan081] approach
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price);
priceTextView.setText("₹ "+ number);
}
After latest update of Android studio it should be this code in Kotlin:
/**
* This method displays the given price on the screen.
*/
private fun displayPrice(number: Int) {
val priceTextView = findViewById(com.example.justjava.R.id.price_text_view) as TextView
priceTextView.setText(java.text.NumberFormat.getCurrencyInstance().format(number))
}
That was really awesome Thanks!