Bug 1668492: Stop using locale based decimals when saving printing prefs. r=jwatt

Differential Revision: https://phabricator.services.mozilla.com/D92099
This commit is contained in:
Bob Owen 2020-10-01 17:55:01 +00:00
Родитель a63466e44e
Коммит 922f287afd
1 изменённых файлов: 13 добавлений и 6 удалений

Просмотреть файл

@ -904,19 +904,26 @@ nsresult nsPrintSettingsService::ReadPrefDouble(const char* aPrefId,
nsAutoCString str; nsAutoCString str;
nsresult rv = Preferences::GetCString(aPrefId, str); nsresult rv = Preferences::GetCString(aPrefId, str);
if (NS_SUCCEEDED(rv) && !str.IsEmpty()) { if (NS_FAILED(rv) || str.IsEmpty()) {
aVal = atof(str.get()); return NS_ERROR_NOT_AVAILABLE;
} }
return rv;
double value = str.ToDouble(&rv);
if (NS_FAILED(rv)) {
return rv;
}
aVal = value;
return NS_OK;
} }
nsresult nsPrintSettingsService::WritePrefDouble(const char* aPrefId, nsresult nsPrintSettingsService::WritePrefDouble(const char* aPrefId,
double aVal) { double aVal) {
NS_ENSURE_ARG_POINTER(aPrefId); NS_ENSURE_ARG_POINTER(aPrefId);
nsPrintfCString str("%6.2f", aVal); nsAutoCString str;
NS_ENSURE_TRUE(!str.IsEmpty(), NS_ERROR_FAILURE); // We cast to a float so we only get up to 6 digits precision in the prefs.
str.AppendFloat((float)aVal);
return Preferences::SetCString(aPrefId, str); return Preferences::SetCString(aPrefId, str);
} }