Kaydet (Commit) cc8a2d00 authored tarafından Laurent Balland-Poirier's avatar Laurent Balland-Poirier Kaydeden (comit) Eike Rathke

tdf#88835 Calc: General format: 2 digits in exponent

Create 4 new formats enums rtl_math_StringFormat:
rtl_math_StringFormat_E1, rtl_math_StringFormat_E2,
rtl_math_StringFormat_G1, rtl_math_StringFormat_G2
to 1 or 2 digits in exponent for scientific notation.

Set General format to use rtl_math_StringFormat_E2.
Set trendline equation in status bar to use rtl_math_StringFormat_E1

Change-Id: I41466a6d4ba808ba5b9b38ba252b37c6b4560f12
Reviewed-on: https://gerrit.libreoffice.org/14562Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
Tested-by: 's avatarEike Rathke <erack@redhat.com>
üst d1f679ca
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <vector> #include <vector>
#define NUMBER_TO_STR(number) (OStringToOUString(::rtl::math::doubleToString( \ #define NUMBER_TO_STR(number) (OStringToOUString(::rtl::math::doubleToString( \
number, rtl_math_StringFormat_G, 4, '.', true ),RTL_TEXTENCODING_ASCII_US )) number, rtl_math_StringFormat_G1, 4, '.', true ),RTL_TEXTENCODING_ASCII_US ))
#define UC_SPACE (sal_Unicode(' ')) #define UC_SPACE (sal_Unicode(' '))
#define UC_MINUS_SIGN (sal_Unicode('-')) #define UC_MINUS_SIGN (sal_Unicode('-'))
......
...@@ -53,6 +53,26 @@ enum rtl_math_StringFormat ...@@ -53,6 +53,26 @@ enum rtl_math_StringFormat
*/ */
rtl_math_StringFormat_Automatic, rtl_math_StringFormat_Automatic,
/** Same 'E', but with only 1 minimum digits in exponent.
@since LibreOffice 4.5
*/
rtl_math_StringFormat_E1,
/** Same 'E', but with only 2 minimum digits in exponent.
@since LibreOffice 4.5
*/
rtl_math_StringFormat_E2,
/** Same 'G', but with only 1 minimum digits in exponent.
@since LibreOffice 4.5
*/
rtl_math_StringFormat_G1,
/** Same 'G', but with only 2 minimum digits in exponent.
@since LibreOffice 4.5
*/
rtl_math_StringFormat_G2,
/** @cond INTERNAL */ /** @cond INTERNAL */
rtl_math_StringFormat_FORCE_EQUAL_SIZE = SAL_MAX_ENUM rtl_math_StringFormat_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
/** @endcond */ /** @endcond */
......
...@@ -368,13 +368,20 @@ inline void doubleToString(StringT ** pResult, ...@@ -368,13 +368,20 @@ inline void doubleToString(StringT ** pResult,
} }
break; break;
case rtl_math_StringFormat_G : case rtl_math_StringFormat_G :
case rtl_math_StringFormat_G1 :
case rtl_math_StringFormat_G2 :
{ // G-Point, similar to sprintf %G { // G-Point, similar to sprintf %G
if ( nDecPlaces == rtl_math_DecimalPlaces_DefaultSignificance ) if ( nDecPlaces == rtl_math_DecimalPlaces_DefaultSignificance )
nDecPlaces = 6; nDecPlaces = 6;
if ( nExp < -4 || nExp >= nDecPlaces ) if ( nExp < -4 || nExp >= nDecPlaces )
{ {
nDecPlaces = std::max< sal_Int32 >( 1, nDecPlaces - 1 ); nDecPlaces = std::max< sal_Int32 >( 1, nDecPlaces - 1 );
if( eFormat == rtl_math_StringFormat_G )
eFormat = rtl_math_StringFormat_E; eFormat = rtl_math_StringFormat_E;
else if( eFormat == rtl_math_StringFormat_G2 )
eFormat = rtl_math_StringFormat_E2;
else if( eFormat == rtl_math_StringFormat_G1 )
eFormat = rtl_math_StringFormat_E1;
} }
else else
{ {
...@@ -593,9 +600,9 @@ inline void doubleToString(StringT ** pResult, ...@@ -593,9 +600,9 @@ inline void doubleToString(StringT ** pResult,
} }
// Print the exponent ('E', followed by '+' or '-', followed by exactly // Print the exponent ('E', followed by '+' or '-', followed by exactly
// three digits). The code in rtl_[u]str_valueOf{Float|Double} relies on // three digits for rtl_math_StringFormat_E). The code in
// this format. // rtl_[u]str_valueOf{Float|Double} relies on this format.
if( eFormat == rtl_math_StringFormat_E ) if( eFormat == rtl_math_StringFormat_E || eFormat == rtl_math_StringFormat_E2 || eFormat == rtl_math_StringFormat_E1 )
{ {
if ( p == pBuf ) if ( p == pBuf )
*p++ = static_cast< typename T::Char >('1'); *p++ = static_cast< typename T::Char >('1');
...@@ -608,10 +615,11 @@ inline void doubleToString(StringT ** pResult, ...@@ -608,10 +615,11 @@ inline void doubleToString(StringT ** pResult,
} }
else else
*p++ = static_cast< typename T::Char >('+'); *p++ = static_cast< typename T::Char >('+');
// if (nExp >= 100 ) if ( eFormat == rtl_math_StringFormat_E || nExp >= 100 )
*p++ = static_cast< typename T::Char >( *p++ = static_cast< typename T::Char >(
nExp / 100 + static_cast< typename T::Char >('0') ); nExp / 100 + static_cast< typename T::Char >('0') );
nExp %= 100; nExp %= 100;
if ( eFormat == rtl_math_StringFormat_E || eFormat == rtl_math_StringFormat_E2 || nExp >= 10 )
*p++ = static_cast< typename T::Char >( *p++ = static_cast< typename T::Char >(
nExp / 10 + static_cast< typename T::Char >('0') ); nExp / 10 + static_cast< typename T::Char >('0') );
*p++ = static_cast< typename T::Char >( *p++ = static_cast< typename T::Char >(
......
...@@ -1711,27 +1711,27 @@ OUString SvNumberformat::StripNewCurrencyDelimiters( const OUString& rStr, ...@@ -1711,27 +1711,27 @@ OUString SvNumberformat::StripNewCurrencyDelimiters( const OUString& rStr,
return aTmp; return aTmp;
} }
void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUStringBuffer& OutString) void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUStringBuffer& rOutString)
{ {
OUString sTemp; OUString sTemp;
ImpGetOutputStandard(fNumber, sTemp); ImpGetOutputStandard(fNumber, sTemp);
OutString = sTemp; rOutString = sTemp;
} }
void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUString& OutString) void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUString& rOutString)
{ {
sal_uInt16 nStandardPrec = rScan.GetStandardPrec(); sal_uInt16 nStandardPrec = rScan.GetStandardPrec();
if ( fabs(fNumber) > 1.0E15 ) // #58531# was E16 if ( fabs(fNumber) > 1.0E15 ) // #58531# was E16
{ {
nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals
OutString = ::rtl::math::doubleToUString( fNumber, rOutString = ::rtl::math::doubleToUString( fNumber,
rtl_math_StringFormat_E, nStandardPrec /*2*/, rtl_math_StringFormat_E2, nStandardPrec /*2*/,
GetFormatter().GetNumDecimalSep()[0]); GetFormatter().GetNumDecimalSep()[0]);
} }
else else
{ {
ImpGetOutputStdToPrecision(fNumber, OutString, nStandardPrec); ImpGetOutputStdToPrecision(fNumber, rOutString, nStandardPrec);
} }
} }
...@@ -1959,8 +1959,13 @@ void lcl_GetOutputStringScientific(double fNumber, sal_uInt16 nCharCount, ...@@ -1959,8 +1959,13 @@ void lcl_GetOutputStringScientific(double fNumber, sal_uInt16 nCharCount,
{ {
bool bSign = ::rtl::math::isSignBitSet(fNumber); bool bSign = ::rtl::math::isSignBitSet(fNumber);
// 1.000E+015 (one digit and the decimal point, and the five chars for the exponential part, totalling 7). // 1.000E+015 (one digit and the decimal point, and the two chars +
sal_uInt16 nPrec = nCharCount > 7 ? nCharCount - 7 : 0; // nExpDigit for the exponential part, totalling 6 or 7).
double fExp = log10( fabs(fNumber) );
if( fExp < 0.0 )
fExp = 1.0 - fExp;
sal_uInt16 nCharFormat = 6 + (fExp >= 100.0 ? 1 : 0);
sal_uInt16 nPrec = nCharCount > nCharFormat ? nCharCount - nCharFormat : 0;
if (nPrec && bSign) if (nPrec && bSign)
{ {
// Make room for the negative sign. // Make room for the negative sign.
...@@ -1968,7 +1973,7 @@ void lcl_GetOutputStringScientific(double fNumber, sal_uInt16 nCharCount, ...@@ -1968,7 +1973,7 @@ void lcl_GetOutputStringScientific(double fNumber, sal_uInt16 nCharCount,
} }
nPrec = ::std::min(nPrec, static_cast<sal_uInt16>(14)); // limit to 14 decimals. nPrec = ::std::min(nPrec, static_cast<sal_uInt16>(14)); // limit to 14 decimals.
rOutString = ::rtl::math::doubleToUString(fNumber, rtl_math_StringFormat_E, rOutString = ::rtl::math::doubleToUString(fNumber, rtl_math_StringFormat_E2,
nPrec, rFormatter.GetNumDecimalSep()[0]); nPrec, rFormatter.GetNumDecimalSep()[0]);
} }
...@@ -2129,7 +2134,7 @@ bool SvNumberformat::GetOutputString(double fNumber, ...@@ -2129,7 +2134,7 @@ bool SvNumberformat::GetOutputString(double fNumber,
sal_uInt16 nStandardPrec = rScan.GetStandardPrec(); sal_uInt16 nStandardPrec = rScan.GetStandardPrec();
nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals
sBuff = ::rtl::math::doubleToUString( fNumber, sBuff = ::rtl::math::doubleToUString( fNumber,
rtl_math_StringFormat_E, nStandardPrec /*2*/, rtl_math_StringFormat_E2, nStandardPrec /*2*/,
GetFormatter().GetNumDecimalSep()[0], true); GetFormatter().GetNumDecimalSep()[0], true);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment