Subject Re: [firebird-support] cast 'nnn,nn' to float
Author Michael Ludwig
danyschaer schrieb am 27.11.2008 um 19:54:09 (-0000):
>
> I am working with a table that have into varchar fields some floating
> values, but they use a comma as decimal separator (regarding regional
> settings).
>
> Is it possible to cast this values to floating point values??

I don't think so. You'll have to convert them, replacing commas with
dots.

Firebird 1.5 comes with only a minimal set of SQL functions, and it
doesn't look like that has changed in 2.0. Nothing in there to do string
replacement. Don't know about 2.1, nor which version you're using.

You may find an external function (UDF) somewhere that does the
necessary string replacement for you.

> ... so I can run filters like:
>
> select fff from ttt where cast(fff as float) > 100

I'd consider adding a DECIMAL or FLOAT column to your table to receive
the proper versions of your "floating values", and then do the
conversion in a one-off script using the API of your choice. Something
like Perl or Java or whatever should give you full control over the
up-conversion process.

And then I'd drop that floating VARCHAR, provided it isn't needed any
more.

Michael Ludwig