0

I am using spring boot and angular in which angular is removing trailing zero from a float data type object coming from the response.

For example, angular changes 10.00 to 10. However, using postman I can clearly see that the value is fine in postman that is 10.00

Please suggest some fix / solution in this case.

James Z
  • 12,209
  • 10
  • 24
  • 44
Avishkar
  • 42
  • 1
  • 8
  • Have a look here: https://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places – Vojtone May 31 '22 at 21:05
  • @Vojtone thanks for the reply. but this is not the response I wanted to know. I request you to kindly re-read my question please. – Avishkar Jun 01 '22 at 06:50

1 Answers1

0

Normally, 10 and 10.00 be that same value.

I don't know what is your core issue about the decimal place, but for display the value is can be simple like

Angular (Js, Ts)

<span> {{ data | number: '1.2-2' }} </span>

Spring boot (JAVA)

System.out.printf("%.2f", val);
paranaaan
  • 1,626
  • 2
  • 9
  • 17
  • @paranaan thanks for the reply. But, i cannot use pipe beacuse I am talking about json object not html element. – Avishkar Jun 01 '22 at 06:51
  • Why not, inject `DecimalPipe` in to your component and use like `this.decimalPipe.transform(num, '1.2-2');` – paranaaan Jun 01 '22 at 06:59
  • I appreciate the response. But, I am getting a proper value from spring boot rest api but the thing is that angular is changing the value from float to int if it is ending with 00 or 0 – Avishkar Jun 01 '22 at 12:52