|
| 14 Dec 2016 06:58 PM |
I'm new to advanced string manipulation, so wiki links would be appreciated when answering :)
I'm trying to make a program to count the significant figures in a number, 304 has 3 significant figures, 0.03 have 1 significant figure, etc. As far as I know, there's no function to count significant figures, so does anyone have ideas for how to go about this? I don't want a program, just a method, or a helpful wiki link. |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 06:59 PM |
significant figures? mind defining that
Formerly ToxicDominator - add 30,319 posts |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 06:59 PM |
(string.find(input, '.') or string.len(input) - 1)
Assuming it's always a number. I haven't actually tested this, sorry. |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:00 PM |
((string.find(input, '.') or string.len(input)) - 1)
sorry, this one. i had made an error with precedence i think |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:02 PM |
whoops
function SFigures(input) return ((string.find(input, '%.') or string.len(input)) - 1) end |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:03 PM |
jesus i'm posting too fast sorry for not checking the actual freaking output of my code
function SFigures(input) return string.find(input, '%.') and string.find(input, '%.') - 1 or string.len(input) end |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:03 PM |
| #################################################################################################################################################################################### |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:06 PM |
@guy who posted somewhere above me
i think significant figures = significant digits
u can google that if u dont know what it is |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:07 PM |
@Unsub google significant figures, can't post a link :(
@Real That's not what I'm looking for, again, google significant figures. If I run SFigures(100) it returns 3, which is incorrect, 100 has 1 significant figure.
|
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:11 PM |
function SFigures(input) local s,e = input:find("[1-9][%d%.]*[1-9]*") return e - s + (input:sub(s,e):find('%.') and 0 or 1) end
I've got no idea if this is what you're looking for. |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:12 PM |
By significant figures, do you mean the figures that would need to be expressed when writing a number in scientific notation?
I'm kind of lost here. |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 14 Dec 2016 07:20 PM |
There are three rules on determining how many significant figures are in a number:
Non-zero digits are always significant.
Any zeros between two significant digits are significant.
A final zero or trailing zeros in the decimal portion ONLY are significant.
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:20 PM |
Significant figures are defined by a few rules:
1. All nonzero digits are significant. (1-9)
2. All 0's after the decimal point and after a nonzero digit are significant (3.00 has 3 sig figs)
3. All 0's between two significant figures are significant (100 has 1 significant figure but 100.0 has 4. 1 is a significant figure, and the .0 is after a decimal and after a nonzero number so it is significant, the two zeros in between are significant because of this.)
Google it if you don't understand |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2016 07:41 PM |
function SD(input) if type(input) == 'number' then input = '' .. input end s,e = input:find("[1-9]-%.*%d*") return (e - s) + (input:sub(s,e):find('.') and 0 or 1) end
i think i did it |
|
|
| Report Abuse |
|
|
| |
|