What would be the RAML equivalent of xsd:decimal?


I am not allowed to use floating point to represent amounts. What would be the correct way to implement xsd:decimal in RAML? Do I have to write a custom type?



I think you can use number for that purpose.


According to the RAML spec,

The value MUST be one of the following: int32, int64, int, long, float, double, int16, int8.

None of these formats are appropriate for a currency value.


Why not using float as your format for any decimal? I don’t understand why currencies cannot represent using that? Where do you think you miss something?


Not all numbers have an exact representation in float.




Not sure what’s the best way is here since I don’t see the problem with what you have there. From the articles, you linked here you see that you don’t have decimal in most languages as well. It seems to me that there is no coherent approach at the moment. So either you use integer (that’s what some suggest), float (which is not perfect), or create your own decimal type.


Integers can’t represent quantities with cents and float creates unacceptable rounding error for financial messages. XML has xsd:decimal for example, SQL has a decimal type, Java has DecimalFormat, and so on with other languages. As you mentioned, others don’t have a built-in type.

I am writing APIs for http://www.ifsf.org that will be used for fuel payment and inventory control. I guess I’ll have to resort to a string with a regexp which is not as elegant as a built in type that can handle currency operations.


What I’d suggest is to raise that as an enhancement request on the raml-spec github repo. Suggest to introduce decimal or a way to better represent currency.


done https://github.com/raml-org/raml-spec/issues/508