How to define money amounts in an API

别等时光非礼了梦想. 提交于 2019-11-30 05:06:20

Integers will eat the dot, that's one less byte :D Integers will have a max_int, do you have anyone rich enough that may overflow?

People that will parse a currency string as float will turn the int to float anyway.

If you send binary data, integer will be much smaller than a string and the way to go. If you send xml anyway, you might as well define it a string (the file is probably compressed before sending right?), try to make it "currency" type as opposed to listing it as a full string though.

Which datatype is the best depends on your usage. For calculations integers or doubles are going to be faster, skipping the parsing step. If sending the data through networks is your goal you're better off with strings.

That said, any functionality should be realizable using either method.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!