How to have sprintf to ignore trailing zeros

前端 未结 2 1697
终归单人心
终归单人心 2021-01-19 01:12

I want to convert a number to a string with at most 15 digits to the right of the decimal point. By at most i mean that if last digits are

2条回答
  •  无人及你
    2021-01-19 01:32

    do you mean this ?

    sprintf('%.15g', 3.0001001)
    ==> 3.0001001
    sprintf('%.15g', 3.0001)
    ==> 3.0001
    

提交回复
热议问题