Norris Boyd wrote:
> On Jul 28, 5:10 am, chris idr <[EMAIL PROTECTED]> wrote:
>   
>> Hi I have this code sent into rhino.
>> event.value = ("%.2f",(p.value*h*i.value/12)/(h-1))
>>
>> p.value=10, h = 5, i.value=5.
>> but this code is not evaluated properly, as I get a value to 7-8 decimal
>> places, how do I make rhino round it to %.2f (2 decimal places) as it says?
>>
>> Or if this would never happen with rhino, what do I have to do to make
>> this call go to my own java class 'acro' which is already within rhino
>> context?
>>
>> Many thanks for help
>>
>> Chris Wade
>>     
>
> The expression ("%.2f", expr) is merely a parenthesized comma
> expression, where "%.2f" is evaluated for its side effects (none) and
> then the result of the expression is the right hand side of the
> comma.
>
> To round expr to 2 decimal places, do
>     Math.round(expr * 100)/100
>
> --N
> _______________________________________________
> dev-tech-js-engine-rhino mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>
>   
cheers noris, I've got it working now I also had to pre-parse the 
javascript to change it from ("%2", value) to util.z("%2",value) so that 
it called my java code to reformat it.
and I added util to be called from the javascript via this

Object defaultJavascript = org.mozilla.javascript.Context.javaToJS( new 
DefaultJavascript(), scope );
        org.mozilla.javascript.ScriptableObject.putProperty( scope, 
"util", defaultJavascript );

Regards

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to