Java Double to String conversion without formatting

前端 未结 9 1315
余生分开走
余生分开走 2020-12-06 09:29

I have the number 654987. Its an ID in a database. I want to convert it to a string. The regular Double.ToString(value) makes it into scientific form, 6.54987E5. Something

9条回答
  •  遥遥无期
    2020-12-06 09:42

    If what you are storing is an ID (i.e. something used only to identify another entity, whose actual numeric value has no significance) then you shouldn't be using Double to store it. Precision will almost certainly screw you.

    If your database doesn't allow integer values then you should stored IDs as strings. If necessary make the string the string representation of the integer you want to use. With appropriate use of leading zeros you can make the alphabetic order of the string the same as the numeric order of the ints.

    That should get you round the issue.

提交回复
热议问题