Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function FormatNum(n:Int64; dec:Byte=3): String;
- var i:Int32; f:Double:=n;
- begin
- while (abs(f) >= 1000) and Inc(i) do f /= 1000.0;
- Result := FloatToStr(Round(f,dec)) + (['','k','m','b','t','qd','qt'])[i-1];
- end;
- function InvFormatNum(str:String): Int64;
- var
- i:Int32;
- n:Double;
- format := ExtractFromStr(str, Letters);
- formats := ['','k','m','b','t','qd','qt'];
- begin
- SetLength(str, Length(str)-Length(format));
- n := StrToFloat(str);
- while (formats[i] <> format) and Inc(i) do n *= 1000.0;
- Result := Round(n);
- end;
- begin
- WriteLn(FormatNum(0));
- WriteLn(FormatNum(500));
- WriteLn(FormatNum(1500));
- WriteLn(FormatNum(1200000));
- WriteLn(FormatNum(1601000000));
- WriteLn(FormatNum(-1500));
- // reversed
- WriteLn(InvFormatNum(FormatNum(0)));
- WriteLn(InvFormatNum(FormatNum(500)));
- WriteLn(InvFormatNum(FormatNum(1500)));
- WriteLn(InvFormatNum(FormatNum(1200000)));
- WriteLn(InvFormatNum(FormatNum(1601000000)));
- WriteLn(InvFormatNum(FormatNum(-1500)));
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement