Improve exposure compensation fraction formatting
This commit is contained in:
parent
8ae8156957
commit
4e3d1dec08
@ -14,6 +14,7 @@ describe('EXIF', () => {
|
||||
it('exposure compensation', () => {
|
||||
expect(formatExposureCompensation(-1)).toBe('-1ev');
|
||||
expect(formatExposureCompensation(0)).toBe(undefined);
|
||||
expect(formatExposureCompensation(0.25)).toBe('+1/4ev');
|
||||
expect(formatExposureCompensation(0.33)).toBe('+1/3ev');
|
||||
expect(formatExposureCompensation(0.333)).toBe('+1/3ev');
|
||||
expect(formatExposureCompensation(0.5)).toBe('+1/2ev');
|
||||
@ -22,8 +23,22 @@ describe('EXIF', () => {
|
||||
expect(formatExposureCompensation(0.015625)).toBe('+1/64ev');
|
||||
expect(formatExposureCompensation(-0.015625)).toBe('-1/64ev');
|
||||
expect(formatExposureCompensation(1)).toBe('+1ev');
|
||||
expect(formatExposureCompensation(-1.33)).toBe('-1 1/3ev');
|
||||
expect(formatExposureCompensation(1.33)).toBe('+1 1/3ev');
|
||||
expect(formatExposureCompensation(1.333)).toBe('+1 1/3ev');
|
||||
expect(formatExposureCompensation(1.3333)).toBe('+1 1/3ev');
|
||||
expect(formatExposureCompensation(1.5)).toBe('+1 1/2ev');
|
||||
expect(formatExposureCompensation(1.9960938)).toBe('+2ev');
|
||||
// Ignore long fractions
|
||||
expect(formatExposureCompensation(-0.119)).toBe('-0.12ev');
|
||||
expect(formatExposureCompensation(-0.112340989)).toBe('-0.11ev');
|
||||
expect(formatExposureCompensation(0.119)).toBe('+0.12ev');
|
||||
expect(formatExposureCompensation(0.112340989)).toBe('+0.11ev');
|
||||
expect(formatExposureCompensation(1.119)).toBe('+1.12ev');
|
||||
expect(formatExposureCompensation(1.112340989)).toBe('+1.11ev');
|
||||
expect(formatExposureCompensation(-1.119)).toBe('-1.12ev');
|
||||
expect(formatExposureCompensation(-1.112340989)).toBe('-1.11ev');
|
||||
expect(formatExposureCompensation(1.9595959)).toBe('+1.96ev');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -42,9 +42,15 @@ export const formatNumberToFraction = (number: number) => {
|
||||
const fraction = decimal !== 0
|
||||
? formatDecimalToFraction(Math.abs(decimal))
|
||||
: '';
|
||||
const sign = number > 0 ? '+' : '-';
|
||||
const whole = integer > 0
|
||||
? fraction ? `${integer} ` : integer
|
||||
: '';
|
||||
return `${sign}${whole}${fraction}`;
|
||||
const sign = number >= 0 ? '+' : '-';
|
||||
// Ensure fractions are not too long
|
||||
if (!fraction || fraction.length <= 4) {
|
||||
const whole = integer > 0
|
||||
? fraction ? `${integer} ` : integer
|
||||
: fraction ? '' : '0';
|
||||
return `${sign}${whole}${fraction}`;
|
||||
} else {
|
||||
const decimalFormatted = decimal.toPrecision(2).replace(/^-*0+/, '');
|
||||
return `${sign}${integer}${decimalFormatted}`;
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user