tdf#106052 Treat SubFormat for "Precision as shown"

Get precision from the correct subformat

Change-Id: I458e5b3d1fb515864f19499ac9ac529e1d68a267
Reviewed-on: https://gerrit.libreoffice.org/34505
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
This commit is contained in:
Laurent Balland-Poirier 2017-02-16 22:15:37 +01:00 committed by Eike Rathke
parent 291c9122b2
commit e7f769bc67
4 changed files with 18 additions and 2 deletions

View file

@ -516,6 +516,9 @@ public:
/// Count of decimals
sal_uInt16 GetFormatPrecision( sal_uInt32 nFormat ) const;
/// Count of decimals with correct subformat according to fValue
sal_uInt16 GetFormatPrecision( sal_uInt32 nFormat, double fValue ) const;
/// Count of integer digits
sal_uInt16 GetFormatIntegerDigits( sal_uInt32 nFormat ) const;

View file

@ -219,7 +219,8 @@ public:
sal_uInt16 GetSubformatIndex( double fNumber ) const;
/// Count of decimal precision
sal_uInt16 GetFormatPrecision() const { return NumFor[0].Info().nCntPost; }
sal_uInt16 GetFormatPrecision( sal_uInt16 nIx = 0 ) const
{ return NumFor[nIx].Info().nCntPost; }
/// Count of integer digits
sal_uInt16 GetFormatIntegerDigits() const { return NumFor[0].Info().nCntPre; }

View file

@ -660,7 +660,7 @@ double ScDocument::RoundValueAsShown( double fVal, sal_uInt32 nFormat ) const
short nPrecision;
if ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) != 0)
{
nPrecision = (short)pFormat->GetFormatPrecision();
nPrecision = (short)GetFormatTable()->GetFormatPrecision( nFormat, fVal );
switch ( nType )
{
case css::util::NumberFormat::PERCENT: // 0.41% == 0.0041

View file

@ -1980,6 +1980,18 @@ sal_uInt16 SvNumberFormatter::GetFormatPrecision( sal_uInt32 nFormat ) const
return pFormatScanner->GetStandardPrec();
}
sal_uInt16 SvNumberFormatter::GetFormatPrecision( sal_uInt32 nFormat, double fValue ) const
{
const SvNumberformat* pFormat = GetFormatEntry( nFormat );
if ( pFormat )
{
sal_uInt16 nIx = pFormat->GetSubformatIndex( fValue );
return pFormat->GetFormatPrecision( nIx );
}
else
return pFormatScanner->GetStandardPrec();
}
sal_uInt16 SvNumberFormatter::GetFormatIntegerDigits( sal_uInt32 nFormat ) const
{
const SvNumberformat* pFormat = GetFormatEntry( nFormat );