Advertisement
Guest User

Untitled

a guest
Mar 1st, 2025
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.37 KB | Source Code | 0 0
  1. import std/[strutils, strformat]
  2.  
  3. proc roundfloat_str(fval: SomeFloat): string =
  4.   strip(&"{fval:.0f}", leading=false, chars={'.'})
  5.  
  6. proc floatStr(fval: SomeFloat): string =
  7.   strip(&"{fval:f}", leading=false, chars={'.', '0'})
  8.  
  9. echo &"{123.45:.0f}"        # 123.
  10. echo roundfloat_str(123.45) # 123
  11. echo floatStr(123.45)       # 123.45
  12. echo floatStr(123.0)        # 123
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement