JavaScript (ES6) (Regex) 142
Regex is great and it can do many things. It can even do maths!
a=('x'.repeat(prompt().replace('.', ''))+'xxxx').match(/^((x*)\2{99}(x{0,99}))\1{4}x{0,4}$/);c=a[3].length;alert(a[2].length+'.'+(c<10?'0'+c:c))
Readable version:
function tip(m) {
var s = 'x'.repeat(m.replace('.', '')) + 'xxxx';
var a = s.match(/^((x*)\2{99}(x{0,99}))\1{4}x{0,4}$/);
var c = a[3].length;
if (c < 10) c = '0' + c;
return a[2].length + '.' + c;
}
The tip()
function expects String argument, rather than Number.
All instances of *
, /
, +
are not related to math operations.
+
is string concatenation in all instances it is used.*
is part of RegExp syntax/
is the delimiter of RegExp literal
The input must use .
as decimal point, and there must be 2 digits after decimal point.
Stack Snippet
<button onclick = "a=('x'.repeat(prompt().replace('.', ''))+'xxxx').match(/^((x*)\2{99}(x{0,99}))\1{4}x{0,4}$/);c=a[3].length;alert(a[2].length+'.'+(c<10?'0'+c:c))">Try it out</button>