have a question about formatting the Rupee currency (Indian Rupee - INR).
For example, numbers here are represented as:
1
10
100
1,000
10,000
1,00,000
10,00,000
1,00,00,000
10,00,00,000
But not able to find any reference library where I can separate comma number in Indian formate.
You can use Intl package as follow:
var format = NumberFormat.currency(locale: 'HI');
print(format.format(100000000));//10,00,00,000.00
You can use Intl package as follow:
final indianRupeesFormat = NumberFormat.currency(
name: "INR",
locale: 'en_IN',
decimalDigits: 0, // change it to get decimal places
symbol: '₹ ',
);
Or,
You can format any number as you want:
final numberFormatter = NumberFormat(
"##,##,###",
"en_US", // local US
)
An Extension to format numbers into Indian currency format:
extension RupeesFormatter on int {
String inRupeesFormat() {
return indianRupeesFormat.format(this);
}
}
use it like this:
Text(
2000.inRupeesFormat(), // output: ₹ 2,000
),
amount.toLocaleString('en-IN', {currency: 'INR', style: 'currency'}) is best jquery function to get Indian thousand comma seperator Format
toLocaleString
var amount="9887977998";
//if amount symbol required
console.log(addCommaSeperatorForAmt(amount,true))
function addCommaSeperatorForAmt(amount, symbolRequired) {
var amountDigit = "";
if (!symbolRequired) {
amountDigit = Number(amount).toLocaleString('en-IN', {currency: 'INR', style: 'currency'}).replaceAll(/₹/g, "");
} else {
amountDigit = Number(amount).toLocaleString('en-IN', {currency: 'INR', style: 'currency'});
}
return amountDigit;
}
Find this Ref:https://www.w3schools.com/jsref/jsref_tolocalestring.asp
Use locale 'en_IN' for English Indian formatting and 'HI' for Hindi Indian formatting
var indiaFormat = NumberFormat.compactCurrency(locale: 'HI');
print(indiaFormat.format(1000000));//10 लाख
var indiaFormat = NumberFormat.compactCurrency(locale: 'en_IN');
print(indiaFormat.format(1000000));//10L
If you want to show amount with ₹ symbol then use the following code:
Text(
NumberFormat.currency(
symbol: '₹ ',
locale: "HI",
decimalDigits: 3,
).format(amount),
),
Don't forget to import the intl package.
Related
I am trying to find a solution to this problem.
I have a text input, and when the user types in the text input "trending". I return a result set of text containing the word trending. What I want to do is display the text that was entered bold (example: trendingitems).
The solution I have currently works, sort of.
String resultText = "trending items";
int x = resultText.toLowerCase().indexOf(queriedText.toLowerCase()); // Problem happens here, I get -1 as a result
List parts = [ // I use this list to display in a Rich Text to adjust the style of the text the user input
if (resultText.substring(0, x).isNotEmpty) resultText.substring(0, x).trim(),
queriedText,
if (resultText.substring(x + queriedText.length).isNotEmpty)
resultText.substring(x + queriedText.length).trim()
];
int idx = resultText.toLowerCase().indexOf(queriedText.toLowerCase());
while (idx > 0 && idx < resultText.length) {
String _subT = resultText.substring(idx + queriedText.length);
idx = _subT.toLowerCase().indexOf(queriedText.toLowerCase());
}
If the user enters trending items but the result set has trendingitems, int x is returned a value of -1 which is where the widget crashes (understandably).
What I would like to get is the following:
This scenario works:
User types: trending
Display: trending items in the list
This scenario crashes:
User types: trending items
Display: trending items in the list
TIA
I've made a package for this: text_chunk_styling
dependencies:
text_chunk_styling: ^2.0.1
Basically it will apply a custom TextStyle to some part of your text in your case the code would be something like this:
Sample 1
TextChunkStyling(
text: 'trending items',
highlightText: const ['trending'],
highlightTextStyle: const TextStyle(fontWeight: FontWeight.bold),
)
Sample 2
TextChunkStyling(
text: 'trending items',
highlightText: const ['trending items'],
highlightTextStyle: const TextStyle(fontWeight: FontWeight.bold),
)
Hi guys I'm trying to remove or hide the last letter from List
Any possible ways?
Text(list[i].name,
style: GoogleFonts.poppins(
fontWeight: FontWeight.w400,
color:
list[i].isBook == "0"
? selectedTimingSlot[i] ? WHITE : BLACK
: Colors.grey.withOpacity(0.5),
fontSize: 15,
),
),
**Above code shows= "12:00 AM" I need to hide or remove "AM"**
Use substring method:
main() {
print("12:00 AM".substring(0,5));
}
Or with replaceAll method:
main() {
print("12:00 AM".replaceAll("AM","").replaceAll("PM",""));
}
with regular expression:
main() {
var regex = new RegExp(r'[a-zA-Z]');
print("02:00 AM".replaceAll(regex,""));
}
Ketan’s substring method is a terrible way of doing this, what about “9:00 PM”?
Edit: looks like his method worked perfectly!
Use regex and/or the following package:
https://pub.dev/packages/string_validator
The way I do it is with this extension
extension StringExtension on String {
String deleteLastChar({int toDelete = 1}) => substring(0, length - toDelete);
}
And you can use like
"12:00 AM".deleteLastChar(toDelete: 3) // Prints 12:00
Why toDelete: 3? Because you also want to remove the space between 12:00 and AM
In my flutter application I'm using qcf_bsml font, I have to generate the hex values to display the corresponding words in the font file. For that, I'm using this equation:
(64396 + Id >= 64434) ? 64429 + chapterId : 64396 + Id
I convert the result from above to hex value using this function:
calculatehex(){
final myInteger = (64396 + 1 >= 64434) ? 64429 + 1 : 64396 + 1; //Id is 1: result 64397
final hexString = myInteger.toRadixString(16);
final paddedString = hexString.padLeft(4, '0');
uppercaseString = paddedString.toUpperCase();
print(uppercaseString); //displays correct hex value in console :FB8D
}
The problem is I am only able to hardcode the hex value in text field to display the correct word. For example:
new Text('\u{FB8D}',textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ), // works fine
But if I use the variable name to display text, it displays the wrong word.
new Text(uppercaseString,textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ), // not showing correct word
I tried to concatenate the string like this, but still not working fine
new Text(r'\u{'+uppercaseString+'}',textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ),
Please help me understand why is it display the correct word with hardcoded value with '\u' but not with variable. Thank you
I solved it by using String.fromCharCode(int.parse()) & making following changes in the code:
uppercaseString = paddedString.toUpperCase();
finalhexString ='0x$uppercaseString';
then:
new Text(String.fromCharCode(int.parse(finalhexString)),textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ),
I want "1.284,00 AOA" instead of the default "AOA 1.284,00".
final Function currencyFormat = NumberFormat.currency(
decimalDigits: 2,
symbol: 'AOA',
).format('1284'); /// Current: AOA 1.284,00
You can use following code :
NumberFormat.currency(locale: 'eu', symbol: 'AOA').format(123456);
More examples here : https://www.woolha.com/tutorials/dart-formatting-currency-with-numberformat
I need to display the combining overline character (unicode U+0305) over some other characters, like '2' or 'x'.
https://www.fileformat.info/info/unicode/char/0305/index.htm
Is there a way to accomplish this in Dart?
Thanks in advance.
You can combine by placing the unicode right after the letter:
String overlined = 'O\u{0305}V\u{0305}E\u{0305}R\u{0305}';
print(overlined); // Output: O̅V̅E̅R̅
A more dynamic version (with simplistic logic) would be:
void main() {
String overlined = overline('I AM AN OVERLINED TEXT');
print(overlined); // Output: I̅ A̅M̅ A̅N̅ O̅V̅E̅R̅L̅I̅N̅E̅D̅ T̅E̅X̅T̅
}
String overline(String text) {
return text.split('').map((String char) {
if (char.trim().isEmpty)
return char;
else
return '$char\u{0305}';
}).join();
}
However, this is pretty much limited. A better approach would be using the style property of Flutter's Text to do so:
const Text(
'OVER',
style: TextStyle(decoration: TextDecoration.overline),
);