What would be the RAML equivalent of xsd:decimal?


#1

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?

Thanks


#2

I think you can use number for that purpose.


#3

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.


#4

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?


#5

Not all numbers have an exact representation in float.

http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency

http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/


#6

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.


#7

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.


#8

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.


#9

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