Flow or java service?

Hi,

I have to write a service for the following rule

If a = 0 then b=VALUE
If Value.Length > a then insert “.” at position (Value.length-a)
if Value.Length <= a then concat “0.” and x times “0” (where x=a-value.length) and VALUE.

For eg.:
VALUE=2846 and a=2 then the output should be 28.46
and if VALUE=870 and a=5 then the output should be 0.00870.

is there any method of doing this in flow? or its only possible with java? what shud be the logic for java service?

There is no problem to do this in flow :wink:

Noramlly I’d say write it using FLOW. But in this case you can leverage the BigDecimal class to do this for you. Take a look at the moveDecimalLeft method.

Structure the service this way:

name: movePointLeft
inputs: value, n (both as strings)
outputs: value (a string)

Get value and n from the pipeline using IDataUtil methods (getString and getInt respectively)
Create a new BigDecimal object, passing value to the constructor
Call the BigDecimal.movePointLeft method, passing n
Call the BigDecimal.toString method and put the returned string in the var named value in the pipeline