Split by 4 chars and merge the last block with a different type of glue
JavaScript
function formatar_valor(str) {
var split = str.match(/.{1,4}/g),
join = split.join('.');
return join.replace(/\.(?!.*?\.)/, '-');
}
alert(formatar_valor('1234213412341'));