Solved

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

  • 27 March 2018
  • 4 replies
  • 5 views

Badge

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
icon

Best answer by david_r 27 March 2018, 19:27

View original

4 replies

Userlevel 4

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.

Badge

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.

 

 

Badge

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!

 

 

Userlevel 4
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