[ 
https://issues.apache.org/jira/browse/GROOVY-11569?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17927600#comment-17927600
 ] 

ASF GitHub Bot commented on GROOVY-11569:
-----------------------------------------

paulk-asert commented on PR #2152:
URL: https://github.com/apache/groovy/pull/2152#issuecomment-2661947443

   Actually, I just remembered String::formatted. It allows:
   
   ```
   def nums = (2..7).collect { 1 / it }
   assert nums.collect('%.2f'::formatted) == ['0.50', '0.33', '0.25', '0.20', 
'0.17', '0.14']
   ```
   
   Only for JDK15+, but I can live with that. I'll close the PR/issue.




> Create a sprintf shortcut for 1-arg usage
> -----------------------------------------
>
>                 Key: GROOVY-11569
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11569
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> Currently we support:
> {code:groovy}
> var x = 1/3
> assert sprintf('%5.3f', x) == '0.333'
> {code}
> Or you can use:
> {code:groovy}
> assert String.format('%5.3f', x) == '0.333'
> {code}
> I propose we also support:
> {code:groovy}
> assert x.sprintf('%5.3f') == '0.333'
> assert [x, x, x]*.sprintf('%5.3f') == ['0.333', '0.333', '0.333']
> {code}
> It is intended to be a shortcut only for format strings containing a single 
> format specifier (or at least referencing a single argument).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to