convert number to string without adding decimal point

963 views
Skip to first unread message

Jonathon Paarlberg

unread,
Nov 6, 2015, 11:43:16 AM11/6/15
to OpenRefine
Hi, all. I'm sure there must be a simple solution to this.

How do I convert a number to a string without adding a decimal point. When I convert an ID number to a string, the resulting ID number will have a decimal point and a trailing zero; this is problematic as just doing a value.replace(".0","") thus replacing the decimal point and trailing zero seems to operate even on text (never interpreted by OpenRefine as numbers) that doesn't contain them.

Thanks for any help you can offer.

John Little

unread,
Nov 6, 2015, 2:33:07 PM11/6/15
to OpenRefine
Here are two expressions that should work:  

value.toString().replace(/(\d+)\.(\d+)/,"$1")  
or
value.toString().split(".")[0]

--John

--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Owen Stephens

unread,
Nov 7, 2015, 3:13:16 AM11/7/15
to OpenRefine
You should be able to do this using 'round' before 'toString':

value.round().toString()

Of course if any of the original numbers have something other than '0' after the decimal point this will round them to an integer value

Jonathon Paarlberg

unread,
Nov 9, 2015, 12:44:40 PM11/9/15
to OpenRefine
Thanks. I'll try those out.
Reply all
Reply to author
Forward
0 new messages