daily pastebin goal
88%
SHARE
TWEET

Untitled

a guest Mar 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- code compiled by Roblox-TS
  2. local _exports;
  3. local getSignificantDigits = function(n)
  4.     local str = tostring(n);
  5.     local a, b, num = str:find("(%-?%d+%.?%d*)");
  6.     if b then
  7.         local magStr = str:match("e([+-]%d+)", b + 1);
  8.         local magnitudeStr = (magStr and ("e") .. magStr or "");
  9.         if tonumber(str) == n then
  10.             return str;
  11.         else
  12.             str = ((num)):sub(1, -2);
  13.             local diff = tostring(n - tonumber((str) .. magnitudeStr));
  14.             local extraDigitA, extraDigitB, extraDigitC = diff:match("%-?(%d+)%.?(%d*)e?%-?(%d*)");
  15.             if extraDigitA then
  16.                 local extraDigits = ((extraDigitA)) .. extraDigitB;
  17.                 local posA = str:find(".", 1, true);
  18.                 local firstSigFig = (#str) - (posA or 0) + 1;
  19.                 if extraDigitC ~= "" then
  20.                     extraDigits = (("0"):rep((tonumber(extraDigitC) or 0) - firstSigFig)) .. extraDigits;
  21.                 else
  22.                     extraDigits = extraDigits:sub(firstSigFig + 1);
  23.                 end;
  24.                 do
  25.                     local i = 1;
  26.                     while tonumber((str) .. magnitudeStr) ~= n do
  27.                         str = (str) .. (extraDigits:sub(i, i));
  28.                         if i > 200 then
  29.                             return error(("Couldn't get accurate number: ") .. n);
  30.                         end;
  31.                         i = i + 1;
  32.                     end;
  33.                 end;
  34.                 return (str) .. magnitudeStr;
  35.             end;
  36.         end;
  37.     end;
  38.     return error(("Couldn't match number: ") .. n);
  39. end;
  40. _exports = getSignificantDigits;
  41. return _exports;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top