Decimal Multiplication of Strings
Java 7, 89
void g(char[]a,float b){for(int i=0,l=a.length;i<(int)(l*b);)System.out.print(a[i++%l]);}
takes char[] and float and outputs to STDOUT. basic looping.
JavaScript (ES6), 50 bytes
Edit 2 bytes more to include definition of function f
. 1 byte less using the tip of @manatwork. Note: using ~
we have more iterations than necessary, but this is code golf and even 1 byte counts
f=(s,n,l=s.length*n)=>~n?f(s+s,n-1,l):s.slice(0,l)
TEST
f=(s,n,l=s.length*n)=>~n?f(s+s,n-1,l):s.slice(0,l)
//TEST
console.log=x=>O.textContent+=x+'\n'
;[
['test case', 1, 'test case'],
['case', 3.5, 'casecasecaseca'],
['(will add more later)', 0.3333, '(will '],
['cats >= dogs', 0.5, 'cats >']]
.forEach(t=>{
var s=t[0],n=t[1],x=t[2],r=f(s,n);
console.log("«"+s+"» "+n+' => «'+r+'» '+(x==r?'OK':'FAIL expected '+x));
})
<pre id=O></pre>
Pyth, 9 8
s@Lz*lzQ
Saved 1 byte thanks to Pietu1998
This takes floor(n * len(string))
letters from the string, using cyclical indexing. I believe this is always equivalent to the given formula.
Test Suite