v.oddou
v.oddou

Reputation: 6775

Format (a float to string with no decimals) in nim

I have a float, say 14.55e9 and I want to stringify it to "14550000000" the most nimic, clean and performant way as possible.

For now I only could find something based on slicing: $myFloat[0..$myFloat.find('.')]

The formatFloat method from strutils outputs "14550000000.0" if you ask for precision=0

Upvotes: 0

Views: 698

Answers (1)

zetawars
zetawars

Reputation: 1071

you can use

import json, math
var intvalue = int(math.floor( 14.55));
echo  %*(intvalue);

EDIT: Sorry i posted some javascript code. Math is lowercase in Nim and JSON.stringify was from javascript

Upvotes: 1

Related Questions