A four-round function

zhaozj2021-02-16  45

This is a four-round function, specific usage myround (1.999, 2) = 2.00 The first bit 1.999 is the number of rounds to be rounded, 2 is the decimal place to take.

Welcome everyone to test. QQ: 81392790

Function myround (const yuan: integer): extended; // an: The original floating point number, PP retains the second number of VAR P, L, M, L2: longint; s: String; // Points SQ: String; // Decimal Point SH: String; // Decimal point Begin if Yuan = 0 THEN EXIT; // Original floating point number 0 IF PP <0 THEN EXIT; // The second few digits after the illegal decimal point s: = floattostr (yuan); p: = POS ('.', s); // decimal point position SQ: = MIDSTR (S, 1, p-1); sh: = midstr (S, P 1, Length (s) - Length (SQ) -1); L: = Length (sh); // Dumer number L2: = Length (sq); // Integer number if PP> = l1n begin // 0 Result: = strawloat (s ); Exit; //, such as 11.06, the third place to retain the decimal point, obviously unreasonable end; // {if pp = L THEN //, such as 11.06 To retain the second digit after the decimal point, the second place does not have to return to Begin // 1 results: = S; EXIT; END; // 1} if PP = 5 THEN IF PP> = 1 THEN / / The first, 2 after the decimal point is left. . . BE: = MIDSTR (SH, 1, PP); SH: = INTOSTR (STRTOINT (SH) 1); if Length (sh)> PP THEN BEGIN SH: = Midstr (SH, 2, PP) ; SQ: = INTOSTR (STRTOINT (SQ) 1); End; Result: = STRTOFLOAT (SQ '.' Sh); EXIT; END / / 3 ELSE / / Retained 0-bit Begin // 4 SQ [L2]: = CHR (ORD (SQ [L2]) 1); Result: = STRTOFLOAT (SQ); EXIT; END; // 4 END ELSE BEGIN IF PP> = 1 THEN / / Retain 1 after the decimal point ,2. . . BEGIN / / 3 sh: = midStr (SH, 1, PP); Result: = STRTOFLOAT (SQ '.' Sh); EXIT; END / / 3 ELSE // Retained 0th Begin // 4 Result: = strTOFLOAT (SQ); exit; end; // 4 end; end; // 2nd;

转载请注明原文地址:https://www.9cbs.com/read-21961.html

New Post(0)