Hi,
What I am doing wrong or is it a bug - I could not get right number formating of a fileld:
Either using sprintf (%05.2F) or number format (9,999.99) I am getting following results:
125.456 -> 125.00
Instead I need:
125.456 -> 125.46
12 -> 12.00

brgds
Janeks

Comments

Pierre.Vriens’s picture

Janeks, I'd be happy to try to help you (and David?) find the answer to your question, by trying to recreate your issue in a similar environment, and then let you know about my results. And potentially also with an actual answer (or confirmation as a "bug"). If appropriate, I'd also add it to my list of additional documentation requests (to be added somewhere in the HELP rpts in the future).

To do so, can you provide some (a bit more) details please, i.e. the relevant steps to recreate your issue by somebody familiar with creating forena rpts using the various report editor features? Eventually by sharing the relevant part of your frx, or sql, etc. If the issue can be created with a (variation of a) sample report, that for sure simplifies things (a) for you to provide more details and (b) for me to actually recreate it.

To be complete: from the sample you gave, I think I do understand the results you actually get, versus the results you would want to get (and I agree it should be as you 'want' them to be). But if I don't understand the issue, I can impossibly try to document or fix it ... right?

Pierre.Vriens’s picture

Janek, a related question/suggestion: how about using 'round' instead of sprintf, as explained on http://us3.php.net/manual/en/function.round.php

Example #1 there seems to contain a sample similar to your sample (i.e. the 5th in that list), which is this:

echo round(1.95583, 2); // 1.96

janeks’s picture

I am getting from oracle 5019,53 and I am using number format option for that field:

As result I am getting following output in my report:
5,019.00

So to check I tried to reproduce this in sample report active_users, by just adding a field with decimal constant:

--ACCESS=access administration pages
SELECT uid, name, mail, login, status, 12.12458 as dmy FROM {users} 
  WHERE status=1 order by name

And formated the field output in the same way, like above.
Now I got the correct result: 12.12

So my assumption is that there is some incompatibilities in a case of data that comes from oracle.

I'll try to find out more. Probably I should use some specific data type in such cases...

metzlerd’s picture

yes, I see. I don't think forena can understand the default numeric format with the , as the decimal indicator. This may have to do with language settings on oracle, or it may be the field is a text field in oracle. If the latter is the case try adding a CAST statement to your column select, like this:

select cast(mycol as numeric(6,2)) as total from...

But my bet is the decimal characters are specified in your database connection, as described here:
http://docs.oracle.com/cd/E11882_01/server.112/e10729/ch3globenv.htm#NLS...

To overcome this in the date format, I am setting the date format to be ISO standard when I connect to oracle. Do you think it would be appropriate to do so for the numeric format as well. This could change the way all decimals look on your report though if I do, so I wan't to be careful here.

Thoughts?

janeks’s picture

The cast is not helping here - it gives comma as separator any way, as it is in system settings.
But from the docs you linked follows that we can use client or session specific configuration altering.
In my case I'll would prefer not to change client connection settings as on this connection could depend some other software. The best idea IMHO would be to allow use some ALTER SESSION command. In the best case it could be in Data source configuration.

metzlerd’s picture

Near line 48 of FrxOracle.inc there is an ALTER SESSION command to set dates. The most straightforward thing to do is to add another to this list. If someone comes up with a use case for this I can always add a setting later, but I'm inclined to not provide the configuration option, since the , based decimal doesn't really work right in Forena. IF there are no objections, I'll proceed in this fashion.

janeks’s picture

Hm, there are languages where standard for decimal separator is coma.

My idea was not to provide fixed ALTER SESSION command for orcale driver in Forena, but give it as option so a user could set up (if needed) for his data connection.

I a bit did not got idea from last message, because now there is a problem, that I am getting comma(,) as decimal separator and therefore the formating does now work right. If I would be the possibility to configure decimal separator coming from Orcale to dot (.), than it will work.

brgds
Janeks

metzlerd’s picture

I a bit did not got idea from last message, because now there is a problem, that I am getting comma(,) as decimal separator and therefore the formating does now work right.

Did you mean "does not work right". If so, that's my point. PHP will never cast numbers properly that come out with a "," as a decimal separator, which will give all kinds of problems for casting data in the data typing and formatting features. This is why I suggested that we might make this the normal behavior. If I were to provide it as an option I would want to put in disclaimers that many of the features of forena would break when using this option. (cause they will).

Do you still think we need to provide the option or should it be handled by formatting functions like you are trying to do?

janeks’s picture

ah, o'k - than clear - I do not need this :)
Then it could be "hardcoded".

brgds
Janeks

metzlerd’s picture

Status: Active » Fixed

Ok this has been done and commited in the dev branch and will be available in the next release. I haven't had a chance to test it yet (don't have oracle on my mac), but will a bit later at work today. Code is avialable via git for testing.

Status: Fixed » Closed (fixed)
Issue tags: +

Automatically closed - issue fixed for 2 weeks with no activity.