If we put the value 100g into a NSUnit and use NSMeasurementFormatterUnitOptionsNaturalScale to get a translated String, the result is 3.52 oz for Imperial system. The problem is with Metric, the result is 0,1 kg which is the good value but i need to keep 100g. It's for a recipe and and it's more common to keep "g" when the value is below 1 kg.
Tested with meters the problem don't exist, 100m is 100m in metric probably because meter is the base value like kg (and not g).
Is there a way to force it to have a value over 1 instead of 0,xx ?
NSUnitMass *g = [NSUnitMass grams];
NSMeasurement *measurementGramm = [[NSMeasurement alloc] initWithDoubleValue:100 unit:g];
NSMeasurementFormatter *formatter = [[NSMeasurementFormatter alloc] init];
[formatter setUnitOptions:NSMeasurementFormatterUnitOptionsNaturalScale];
NSLog(@"NSMeasurementFormatterUnitOptionsNaturalScale ---------- %@", [formatter stringFromUnit:g]);
To make it easier, I assume that stored value is based on kg.
NSLogresultHere we can see that we have a value of
0.1and unit inkg.We can convert the
unitif thevalueis below1NSLogresultThe result is still in
kg, this is caused byunitOptionsWe just have to change that
NSLogresultFull code