Below is my sample code
<dw:transform-message doc:name="Transform Message" >
<dw:set-payload><![CDATA[ %dw 1.0
%output application/json skipNullOn = "everywhere"
%function addTrailingZeros (numberWithoutTrailingZeros) (
numberWithoutTrailingZeros as :number {class: "java.lang.BigDecimal"}
)
---
"test" : addTrailingZeros(12.00)
]]></dw:set-payload>
</dw:transform-message>
Output i am getting is
{
"test": 12
}
But i want this { "test": 12.00 }
I tried with {format:"#.00"} but it's not working. If you pass 12.01 its working.
Kindly help me on this issue. Even simplest example
{"test" : 7.00 as :number {format:'#.###'}}
not working
JSON numbers don't retain format. See this answer for a technical explanation of the limitations of numbers in JSON see https://stackoverflow.com/a/38357877/721855 If you need to retain a fixed number of decimal positions you could use a string instead. This is the same as printing a formatted decimal. Printing converts to a string the number.
Check using this:
{
Book: payload.mybook as :string {format: ".00"}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.