Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Use locale sensitive DecimalFormat for color alpha conversion #13393

Merged
merged 1 commit into from
Nov 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.mapbox.mapboxsdk.exceptions.ConversionException;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -147,7 +148,10 @@ public static int rgbaToColor(@NonNull String value) {
* @return String rgba color
*/
public static String colorToRgbaString(@ColorInt int color) {
String alpha = new DecimalFormat("#.###").format(((float) ((color >> 24) & 0xFF)) / 255.0f);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
decimalFormat.applyPattern("#.###");
String alpha = decimalFormat.format(((float) ((color >> 24) & 0xFF)) / 255.0f);
return String.format(Locale.US, "rgba(%d, %d, %d, %s)",
(color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF, alpha);
}
Expand Down