NumberFormat.parse() does not work for FRANCE Locale space as thousand seperator - locale

I have written below Java code to see how locales behave with numbers. I am facing with FRENCH style.
double n = 123456789.123;
System.out.println("US "+ NumberFormat.getNumberInstance(Locale.US).format(n)); //###,###.###
System.out.println("FRENCH "+ NumberFormat.getNumberInstance(Locale.FRENCH).format(n)); // # ###,##
System.out.println("GERMAN "+ NumberFormat.getNumberInstance(Locale.GERMAN).format(n)); // ###.###,##
System.out.println(NumberFormat.getNumberInstance(Locale.US).parse("123,451.23"));
System.out.println(NumberFormat.getNumberInstance(Locale.GERMANY).parse("123.451,23"));
System.out.println(NumberFormat.getNumberInstance(Locale.FRANCE).parse("123 451,23"));
OUTPUT
US 123,456,789.123
FRENCH 123 456 789,123
GERMAN 123.456.789,123
123451.23
123451.23
123
As you can see space is used as thousands separator for FRENCH locale. But when I tried to generate number "123 451,23" it does not recognize space as thousands separator.
Is this the expected behavior ?
EDIT:
As a workaround I replaced space with ".". So number becomes a GERMANY format. And then convert it using that locale.
input = input.replace(" ", ".");
// Now "123 451,23" is "123.451,23" So which is same as german
System.out.println(NumberFormat.getNumberInstance(Locale.GERMANY).parse(input));
OUTPUT
123451.23

This is a known issue in old JDKs. Upgrade it or you will this issue

Related

NPOI: Achieve Currency format as if formatted by Excel

I have seen some questions (like this one) here asking about if a cell in Excel can be formatted by NPOI/POI as if formatted by Excel. As most of you, I have to deal with issues with Currency and DateTime. Here let me ask how the formatting can be achieved as if it has been formatted by Excel? (I will answer this question myself as to demonstrate how to do it.)
Setting: Windows 10, English, Region: Taiwan
Excel format: XLSX (version 2007 and later)
(Sorry about various edit of this question as I have pressed the 'Enter' button at unexpected time.)
If you format a cell as Currency, you have 4 choices:
The internal format of each style is as follow:
-NT$1,234.10
<numFmt formatCode=""NT$"#,##0.00" numFmtId="164"/>
[RED]NT$1,234.10
<numFmt formatCode=""NT$"#,##0.00;[Red]"NT$"#,##0.00" numFmtId="164"/>
-NT$1,234.10
<numFmt formatCode=""NT$"#,##0.00_);("NT$"#,##0.00)" numFmtId="7"/>
[RED]-NT$1,234.10
<numFmt formatCode=""NT$"#,##0.00_);[Red]("NT$"#,##0.00)" numFmtId="8"/>
Note: There is a pair of double quote (") comes before and after NT$.
(To get internal format of XLSX, just unzip it. The Style information is available in <unzip dir>\xl\Styles.xml Check out this answer if you need more information.)
(FYI: In formatCode, the '0' represent a digit. The '#' also represent a digit, but will not appear if the number is not large enough. So any number less than 1000 will not have the comma inside it. The '_' is a space holder. In format 3, '1.75' appears as 'NT$1.75 '. The last one is a space.)
(FYI: In numFmtId, for case 1 and case 2, number 164 is for user-defined. For case 3 and 4, number 7 and 8 are build-in style.)
For developers using POI/NPOI, you may find out if you format your currency column using Build In Format using 0x7 or 0x8, you can get only the third or fourth choice. You cannot get the first or second choice.
To get the first choice, you build upon style 0x7 "$#,##0.00);($#,##0.00)". You need to add the currency symbol and the pair of double quotes in front of it.
styleCurrency.DataFormat = workbook.CreateDataFormat().GetFormat("\"NT$\"#,##0.00");
Apply this format to a cell with number. Once you open the Excel result file, right click to check formatting, you will see the first choice.
Please feel free to comment on this post.
var cell5 = row.CreateCell(5, CellType.Numeric);
cell5.SetCellValue(item.OrderTotal);
var styleCurrency = workbook.CreateCellStyle();
styleCurrency.DataFormat= workbook.CreateDataFormat().GetFormat(string.Format("\"{0}\"#,##0.00", item.CurrencySymbol));//styleCurrency;
cell5.CellStyle = styleCurrency;
styleCurrency = null;
Iterate over loop for multiple currency.
Function to GetCurrencySymbol against currency Code on C#
private string GetCurencySymbol(string isOcurrencyCode)
{
return CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => !c.IsNeutralCulture)
.Select(culture =>
{
try
{
return new RegionInfo(culture.LCID);
}
catch
{
return null;
}
})
.Where(ri => ri != null && ri.ISOCurrencySymbol == isOcurrencyCode)
.Select(ri => ri.CurrencySymbol).FirstOrDefault();}

Thousand separator is not applied by website module odoo9

I have issue in Website odoo with product price séperator
i change the configuration in Settings >Translations >Languages "Thousands Separator" Field
But is not applied in Website(Look picture )
for example 200 000 > in website 200,000
How to delete the comma
I want to display 200 000
Hello friends I found the solution
>>> Go to language setting,
>>> set that you want a ' ' as thousand separator, (Put space)
>> and that works out of the box
>>>> -The only specific case that is if you don't want anything, you need to set an empty char (eg: ​) because by default, we use a comma if no symbol is given ! >>>> [the solution][1] (www.zupimages.net/up/17/25/mnn1.png)
tousand separator : " " ;
[1]: http://zupimages.net/up/17/25/mnn1.png

Tell if specific char in string is a long char or a short char

Be prepared, this is one of those hard questions.
In Farsi or Persian language ی which sounds like y or i and is written in 4 different shapes according to it's place in word. I'll call ی as YA from now for simplification.
take a look at this image
All YA characters are painted in red, in the first word YA is attached to it's previous (right , in Farsi we right from RIGHT to LEFT) character and is free at the end whereas the last YA (3rd word, left-most red char) is free both from left or right.
Having said this long story, I want to find out if a part of a string ends with long YA (YA without points) or short YA (YA with two points beneath it).
i.e تحصیلداری (the 3rd word) ends with long YA but تحصیـ which is a part of 3rd word does not ends with short YA.
Question: How can I say تحصیلداری ends whit which unicode? I just have a simple string, "تحصیلداری", how can I convert its characters to unicode?
I tried the unicodes
string unicodes = "";
foreach (char c in "تحصیلداری")
{
unicodes += c+" "+((int)c).ToString() + Environment.NewLine;
}
MessageBox.Show(unicodes);
result :
but at the end of the day unfortunately all YAs have the same unicode.
Bad news : YA was an example, a real one though. There are also a dozen of other characters like YA with different appearances too.
Additional info :
using this useful link about unicodes I found unicode of different YAs
We solved similar problem the way bellow:
We had a core banking application, the customer sub-system needed a full text search on customers name, family, father name etc.
Different encoding, legacy migrated data, keyboard layouts and Farsi fonts ... made search process inaccurate.
We overcame the problem by replacing problematic characters with some standard one and saving the standard string for search purpose.
After several iterations, the replacement is as bellow that may come in handy:
Formula="UPPER(REPLACE(REPLACE(REPLACE
(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE
(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE
(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE
(REPLACE(REPLACE(REPLACE(REPLACE
(REPLACE(FirsName || LastName || FatherName,
chr(32),''),
chr(13),''),
chr(9),''),
chr(10),''),
'-',''),
'-',''),
'آ','ا'),
'أ', 'ا'),
'ئ', 'ي'),
'ي', 'ي'),
'ك', 'ک'),
'آإئؤةي','اايوهي'),
'ء',''),
'شأل','شاال'),
'ا.','اله'),
'.',''),
'الله','اله'),
'ؤ','و'),
'إ','ا'),
'ة','ه'),
' ا لله','اله'),
'ا لله','اله'),
' ا لله','اله'))"
Despite there are different YEHs in Unicode, it must noticed that all presentation forms of YEHs are same Unicode character with code 0x06cc. You can not determine presentation forms by their Unicode code.
But you can reach your goal be checking to see what characters is before or after YEH.
You can also use Fardis to see Unicode codes of strings.

Importing String with variables from Txt file

I need to import text from txt file with some variables. I use BufferedReader and File Reader. In code I have :
String car = "vw golf";
String color = "nice sunny blue color";
And in my txt file:
I have nice " +car+ " which has "+color+".
My expected output :
I have nice vw golf which has nice sunny blue color.
My actual output is :
I have nice " +car+ " which has "+color+".
If I've understood correctly, what you want to do is replace " + car + " with the value of your car string and likewise for colour. You've tried to do this by writing your text file as if it were a command to be evaluated. However, that won't happen - it will just be outputted as is. I'm going to assume you are using c#. What you need to do is, prior to outputting your string, parse it to replace the markers with the variables. I would recommend you get rid of the double quotes in your text file. You could then do something like this:
string text = this.ReadTextFromFile();
string ammended = text.Replace("+car+", car);
As mentioned, this is assuming you remove the double quotes from your text file so it reads:
I have nice +car+ which has +color+.
Also, you don't need to use the + symbols, but I suppose they are a good way of designating a unique token to be replaced. You could use {car} in the file and then likewise in the Replace startment, for example.
I may not have properly understood what you wanted to do, of course!
Edit: Incase of confustion,
this.ReadTextFile();
was just a short hand way of saying that the text variable contains the contents as read from your text file.

string mutation

I am trying to create a string mutation that, after a prompt for a city and state, would output the state in uppercase, followed directly by the city in lowercase, followed directly by the state again in uppercase.
I have tried many types of mutations but nothing is working.
Can anyone help me?
use String#toUpperCase() and String#toLowerCase() methods.
eg. System.out.println(state.toUpperCase());
Here is one in java
Scanner sc =new Scanner(System.in);
String city,state;
System.out.println("Enter City =");
city=sc.nextLine();
System.out.println("Enter State =");
state=sc.nextLine();
System.out.println( state.toUpperCase() + " "+city.toLowerCase() + " "+ state.toUpperCase());
Independent of any programming language(But dependent on character Representation) you could retrieve every character of string and add 22 which would convert UPPERCASE into LOWERCASE.As you must be knowing ASCII values of a-z is 97-122 and that of A-Z is 65-90.so you can lookout how much to add/ subtract to convert between cases.

Resources