Store 0 as 0.0
Mostrar comentarios más antiguos
Please is it possible to store 0 as 0.0(or 50 as 50.0? I have to save numeric values to json file ( using jsonencode ). I need this specific format due to dependency forward in program chain ( I cannot change the input format of the next block and it is specified that this format is needed). I've spent 4 hours browsing and trying but I am still stuck :( (sprintf('%.1f',var) did not worked... Any help appreciated
2 comentarios
Fangjun Jiang
el 13 de Feb. de 2018
What format do you need to "store", text file? sprintf('%.1f',50) outputs '50.0'. What is the issue?
Jergus Frajt
el 13 de Feb. de 2018
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 13 de Feb. de 2018
0 votos
json files are text files, so if you write your own, using fprintf(), then yes you can do that.
7 comentarios
Jergus Frajt
el 13 de Feb. de 2018
James Tursa
el 13 de Feb. de 2018
The value 0 is the same as the value 0.0 in MATLAB ... they are both numeric double values with exactly the same internal bit pattern (all 0 bits). So we still don't know what your real issue is. An exact 0 does not "display" the .0 part by default, but it is still the same numeric value as 0.0
Image Analyst
el 13 de Feb. de 2018
Why do you even care how it's listed in the json file? What does it matter?
Jergus Frajt
el 13 de Feb. de 2018
Image Analyst
el 13 de Feb. de 2018
Do your other languages throw an error if it's 0 instead of 0.0?
James Tursa
el 13 de Feb. de 2018
No, not really. Numerically 0 and 0.0 are the same, so we assume you mean to write a text file with the output having 0.0 instead of 0. Others have already shown you how to do this with e.g. sprintf( ). Why doesn't this work for you?
Jergus Frajt
el 15 de Feb. de 2018
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!