EgtGeneral 2.7i1 :

- aggiunta ToStringAdv per long long.
This commit is contained in:
Dario Sassi
2025-09-18 10:37:40 +02:00
parent a94693ba8d
commit df77db20d2
2 changed files with 26 additions and 0 deletions
BIN
View File
Binary file not shown.
+26
View File
@@ -152,6 +152,32 @@ ToStringAdv( unsigned int nVal, int nPrec, int nRadix, int* pnErr)
return sBuff ;
}
//----------------------------------------------------------------------------
const string
ToStringAdv( long long nVal, int nPrec, int nRadix, int* pnErr)
{
// eseguo conversione
const int nBuffSize = 68 ;
char szBuff[nBuffSize]{} ;
auto Res = std::to_chars( szBuff, szBuff + nBuffSize - 1, nVal, nRadix) ;
if ( Res.ec != std::errc()) {
if ( pnErr != nullptr)
*pnErr = int( Res.ec) ;
return "#Error" ;
}
// gestione codice di errore
if ( pnErr != nullptr)
*pnErr = 0 ;
// verifico lunghezza minima
int nLen = (int) strlen( szBuff) ;
if ( nLen >= nPrec)
return szBuff ;
// porto la stringa alla minima lunghezza
std::string sBuff( szBuff) ;
sBuff.insert( 0, ( nPrec - nLen), '0') ;
return sBuff ;
}
//----------------------------------------------------------------------------
const string
ToString( double dVal, int nPrec, int* pnErr)