There is also format and drop0trailing
paste0('x',format(y,drop0Trailing = F),'x')
And if you really want to replace 0 with 0.0 , not ( 1.0 or -1.0 ) then
paste0('x',gsub(x = gsub(x = format(y, drop0trailing = T),'0$', '0.0'),' ',''),'x')
Or as @mrdwab suggested (and less typical)
paste0('x',gsub("^0$", "0.0", as.character(y)),'x')
source share