84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
小伙看你根骨奇佳,潜力无限,来学PHP伐。
Is sprintf not efficient enough? Just take out the sprintf function about %f without using the library function.
If you want to omit the processing of % by sprintf, it is recommended to use the _gcvt_s function.
How to use it:
char buffer[320]; _gcvt_s(buffer, 320, number, 30); vint len = (vint)strlen(buffer); if (buffer[len - 1] == '.') { buffer[len - 1] = 'void _gcvt_s(char* buffer, size_t size, double value, vint numberOfDigits) { sprintf(buffer, "%f", value); char* point = strchr(buffer, '.'); if(!point) return; char* zero = buffer + strlen(buffer); while(zero[-1] == '0') { *--zero = 'rrreee'; } if(zero[-1] == '.') *--zero = 'rrreee'; } '; }
void _gcvt_s(char* buffer, size_t size, double value, vint numberOfDigits) { sprintf(buffer, "%f", value); char* point = strchr(buffer, '.'); if(!point) return; char* zero = buffer + strlen(buffer); while(zero[-1] == '0') { *--zero = 'rrreee'; } if(zero[-1] == '.') *--zero = 'rrreee'; }
If the compiler you are using does not have _gcvt_s, you can encapsulate one yourself:
In this way, the program can exert excellent performance under other compilation periods and under VC++.
Why no one mentioned the grisu algorithm. It is the fastest, "completely correct" algorithm Run in the library: https://github.com/night-shift/fpconv
grisu
Is sprintf not efficient enough?
Just take out the sprintf function about %f without using the library function.
If you want to omit the processing of % by sprintf, it is recommended to use the _gcvt_s function.
How to use it:
If the compiler you are using does not have _gcvt_s, you can encapsulate one yourself:
rrreeeIn this way, the program can exert excellent performance under other compilation periods and under VC++.
Why no one mentioned the
grisu
algorithm. It is the fastest, "completely correct" algorithmRun in the library: https://github.com/night-shift/fpconv