Page 1 of 1
numerice (15,0) but want to display as (15,2)
Posted: Thu Jul 11, 2019 1:23 pm
by jflummer
We have a textbox with a value bound to a program field (in a subfile grid)
The data type is decimal and the length is 15 with 0 decimals. Field Formatting = Number. how can i display as (15,2). this is the JDE database file which does not store with decimal positions but users want to see decimal positions. This display file created a while back now business wants the decimals. thanks.
Re: numerice (15,0) but want to display as (15,2)
Posted: Thu Jul 11, 2019 2:39 pm
by riback9
divide by 100 in a work field 15,2 - load the work field to the display.
Re: numerice (15,0) but want to display as (15,2)
Posted: Fri Jul 12, 2019 1:42 am
by Scott Klement
I agree with riback9, that'd be the easiest and most fool-proof method.
Re: numerice (15,0) but want to display as (15,2)
Posted: Fri Jul 12, 2019 8:50 am
by jflummer
thank you. i'll prob do that. There's about 30 numeric fields like this - hoping not to modify the program. was hoping to do via visual designer. maybe in the properties - custom javascript function ? using sql cast or something? just wasn't sure how to make the custom function take a variable so i could use the same function for all the fields. Trying something like this :
function addposdec(gbapyc) {return (num .tofixed(2) )} -- Tried it but didn't work. since these subfile fields are bound, i didn't want to do any code.
Re: numerice (15,0) but want to display as (15,2)
Posted: Fri Jul 12, 2019 2:03 pm
by Scott Klement
If you wanted to do it in the display, you'd probably want to use a custom formatter:
https://core.profoundlogic.com/docs/dis ... +Formatter
However, I can't say I've tried using it for this particular purpose.
Re: numerice (15,0) but want to display as (15,2)
Posted: Fri Jul 12, 2019 3:53 pm
by jflummer
thank you. i did review that documentation previously but not exactly what i needed. instead i tried an alternate valid sQL as the function, but no luck. THIS is the code inside the addposdec.js document: function addposdec(gbapyc) {Cast (gbapyc as decimal(15,2) )}. all i put inside the 'custom javascript function' box was the actual funtion name, as the example shows.... "addposdec" - but how is this variable getting to the function? this is the piece i'm not seeing in the documentation. thanks.
Re: numerice (15,0) but want to display as (15,2)
Posted: Sat Jul 13, 2019 10:34 pm
by Scott Klement
The custom Javascript function must be written in Javascript. It doesn't understand SQL syntax.
The only variable that I see is the parameter passed into the function (called 'params' in the documentation link, above. Or 'gbapyc' in your example.) It gets there because it's passed as a parameter...