1

I have a problem with android code when trying to write a comma delimited CSV file that contains floating point numbers. this problem only happens when the language of the device is set to Deutsch since a comma is used instead of decimal points on this language. so actual decimal points are now considered as a delimiter. and when I open the resulting CSV file the integer parts are in separate columns from the fractional parts. what i want is to force using decimal point in float numbers in all languagees not just to view csv file correctly while keeping the comma instead of the decimal point. how can I solve this problem?

  • You can use another separator, e.g. `;` or `\t`. – Samuel Philipp May 05 '19 at 21:57
  • 1
    or put the values within double quotes `"1,25"` – assylias May 05 '19 at 21:59
  • @assylias, agreed with you - it's better solution because delimiters should be quoted. https://stackoverflow.com/questions/4617935/is-there-a-way-to-include-commas-in-csv-columns-without-breaking-the-formatting?rq=1 – Bor Laze May 05 '19 at 23:06
  • @BorLaze I do not see this Quetion as a duplicate of [that](https://stackoverflow.com/questions/4617935/is-there-a-way-to-include-commas-in-csv-columns-without-breaking-the-formatting). This question is more about localization of number format, not arbitrarily finding a comma in a string. – Basil Bourque May 06 '19 at 19:08
  • 1
    i solved it by using DecimalFormat like this: DecimalFormat df1 = (DecimalFormat) DecimalFormat.getNumberInstance(Locale.ENGLISH); df1.setGroupingUsed(false); df1.setMaximumFractionDigits(1); csvLine.append(df1.format(currLocation.getAltitude())).append(","); what I really was looking for is a way to force using decimal points in float numbers (not to add commas in csv files without breaking the formatting scince this is always possible and easy using "" as in the second comment). thank you all. – bader anini May 08 '19 at 09:03

0 Answers0