Hi @ccomeau I would look into the StringFormatter for a possible solution.
Hope this helps
Hi @ccomeau, had a look at the StringFormatter but couldn't get it working so a couple of AttributeSplitters and an AttributeManager did the job.
french-notation.fmw
Hi @ccomeau, a PythonCaller with this script might help you.
# PythonCaller Script Example: Format a numeric value in French Notation
# Assuming that the feature has an attribute called "value" storing a numeric value.
# Format the numeric value using comma as thousands separator,
# replace commas with spaces, and then replace the decimal point with a comma.
def processFeature(feature):
attr = 'value'
v = float(feature.getAttribute(attr))
s = '{0:,.2f}'.format(v).replace(',', ' ').replace('.', ',')
feature.setAttribute(attr, s)
Hi @ccomeau, a PythonCaller with this script might help you.
# PythonCaller Script Example: Format a numeric value in French Notation
# Assuming that the feature has an attribute called "value" storing a numeric value.
# Format the numeric value using comma as thousands separator,
# replace commas with spaces, and then replace the decimal point with a comma.
def processFeature(feature):
attr = 'value'
v = float(feature.getAttribute(attr))
s = '{0:,.2f}'.format(v).replace(',', ' ').replace('.', ',')
feature.setAttribute(attr, s)
another solution taking advantage of
FME String Functions and
FME Math Functions.
format-number-with-
french-notation.fmw (FME 2016.1.2)
Hi @ccomeau, a PythonCaller with this script might help you.
# PythonCaller Script Example: Format a numeric value in French Notation
# Assuming that the feature has an attribute called "value" storing a numeric value.
# Format the numeric value using comma as thousands separator,
# replace commas with spaces, and then replace the decimal point with a comma.
def processFeature(feature):
attr = 'value'
v = float(feature.getAttribute(attr))
s = '{0:,.2f}'.format(v).replace(',', ' ').replace('.', ',')
feature.setAttribute(attr, s)
At first, I thought this script does the trick.
import locale
class FeatureProcessor(object):
def __init__(self):
locale.setlocale(locale.LC_NUMERIC, 'French')
def input(self,feature):
attr = 'value'
v = float(feature.getAttribute(attr))
feature.setAttribute(attr, locale.format_string('%.2f', v, True))
self.pyoutput(feature)
However, the result is shown like this in my environment - Japanese Windows.
1?000?000,00
I'm curious how the script works in an European locale.
Good morning,
Thank you both for the quick replies. Your FMWs reminded me that I need to update my licence from 2015.1.0.3 as some transformers are not available.
@itay, the FMW you posted works well with millions but smaller and larger numbers do not format correcly. EX. 235 came out as 2 35 . I would need to split from the right. Perhaps flipping the number around then splitting if, then flipping the lists around would work.
@takashi, I had not thought of using Python. Interesting solution option. Sadly, I am a novice programmer and can't get your first solution working. That being said, your second option using the local settings was a novel solution that did work.
Good morning,
Thank you both for the quick replies. Your FMWs reminded me that I need to update my licence from 2015.1.0.3 as some transformers are not available.
@itay, the FMW you posted works well with millions but smaller and larger numbers do not format correcly. EX. 235 came out as 2 35 . I would need to split from the right. Perhaps flipping the number around then splitting if, then flipping the lists around would work.
@takashi, I had not thought of using Python. Interesting solution option. Sadly, I am a novice programmer and can't get your first solution working. That being said, your second option using the local settings was a novel solution that did work.
Hi, true, a remedy would be to test the string lenght beforehand, but that saiud @taskashi 's answer is much more elegant.
Hi @ccomeau, a PythonCaller with this script might help you.
# PythonCaller Script Example: Format a numeric value in French Notation
# Assuming that the feature has an attribute called "value" storing a numeric value.
# Format the numeric value using comma as thousands separator,
# replace commas with spaces, and then replace the decimal point with a comma.
def processFeature(feature):
attr = 'value'
v = float(feature.getAttribute(attr))
s = '{0:,.2f}'.format(v).replace(',', ' ').replace('.', ',')
feature.setAttribute(attr, s)
The regex approach provided by @david_r might be a smarter solution. See this link.
Format number from: 1000000 to 1 000.000