1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-21 11:13:54 +03:00

Add decimal rounding to the sqlite3FpDecode() routine.

FossilOrigin-Name: 27871140caa833f0bc0962e44356993938e93dcf81c1074382b1560a3e1aeb61
This commit is contained in:
drh
2023-06-30 19:41:57 +00:00
parent a1b0ff1735
commit 002330dc48
5 changed files with 44 additions and 18 deletions

View File

@@ -2379,10 +2379,12 @@ static void fpdecodeFunc(
sqlite3_value **argv
){
double r = sqlite3_value_double(argv[0]);
int n = 15;
FpDecode s;
char zBuf[50];
UNUSED_PARAMETER(argc);
sqlite3FpDecode(&s, r);
if( argc>=2 ) n = sqlite3_value_int(argv[1]);
sqlite3FpDecode(&s, r, n);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%c%.*s/%d", s.sign, s.n, s.z, s.iDP);
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
}
@@ -2462,6 +2464,7 @@ void sqlite3RegisterBuiltinFunctions(void){
#if 1 /* Temporary prototyping function */
FUNCTION(fpdecode, 1, 0, 0, fpdecodeFunc ),
FUNCTION(fpdecode, 2, 0, 0, fpdecodeFunc ),
#endif
#ifndef SQLITE_OMIT_FLOATING_POINT