Skip to main content
Solved

Is there an easy way/transformer to turn a fractional string to a decimal number that I'm missing?


Forum|alt.badge.img

Just want to convert from string containing fractional numbers (e.g.,

4 1/2

 

2 7/8

...

to decimal doubles

4.5

2.875

...

Anyway to not use multiple transformers for this? ( I know I can separate the fraction from the whole number, then value map the fractional segment to decimal segments, and then patch the number back together via concatenation...). However, I thought I'd check to see if I'm missing something less bulky.

Many thanks,

 

Pete

Best answer by david_r

Here's a template workspace using a StringSearcher and an ExpressionEvaluator to convert fractions to decimals: fractions.fmwt

Example: "12 3/4" is converted to 12.75

You'll probably have to implement some checks to cover numbers without the trailing fraction and perhaps some other edge cases, but it should be fairly easy.

View original
Did this help you find an answer to your question?

4 replies

david_r
Celebrity
  • Best Answer
  • March 27, 2018

Here's a template workspace using a StringSearcher and an ExpressionEvaluator to convert fractions to decimals: fractions.fmwt

Example: "12 3/4" is converted to 12.75

You'll probably have to implement some checks to cover numbers without the trailing fraction and perhaps some other edge cases, but it should be fairly easy.


Forum|alt.badge.img
  • Author
  • March 27, 2018
david_r wrote:

Here's a template workspace using a StringSearcher and an ExpressionEvaluator to convert fractions to decimals: fractions.fmwt

Example: "12 3/4" is converted to 12.75

You'll probably have to implement some checks to cover numbers without the trailing fraction and perhaps some other edge cases, but it should be fairly easy.

Cool thanks! Very helpful.

 

I believe you meant "12 3/5 is converted to 12.6". Ha ha.

 

 


Forum|alt.badge.img
  • Author
  • March 27, 2018
david_r wrote:

Here's a template workspace using a StringSearcher and an ExpressionEvaluator to convert fractions to decimals: fractions.fmwt

Example: "12 3/4" is converted to 12.75

You'll probably have to implement some checks to cover numbers without the trailing fraction and perhaps some other edge cases, but it should be fairly easy.

Just tried it. Very nice. Thanks again!

 

 


david_r
Celebrity
  • March 28, 2018
pvaziri wrote:
Cool thanks! Very helpful.

 

I believe you meant "12 3/5 is converted to 12.6". Ha ha.

 

 

Whoops, nasty typo, good catch. Fixed :-)

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings