PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 19, 2022

[FIXED] How to declare a numerical variable in java that is to hold a digit value with a fixed length of 3 digits always.

 July 19, 2022     int, integer, java, precision, variables     No comments   

Issue

How to declare a numerical variable in Java that is to hold a digit value with a fixed length of 3 digits always. That is if i input 0, it should be formated to 000, if i input 31 then it should be formated to 032 and if i input 100 then it should remain 100. I need this for receiving and storing three digit integer value that is sent via rest response as error codes. I tried the normal int and Integer but the preceeding zeros are always removed. Thanks for the help.


Solution

It's not a property of a numerical variable, but a way of formatting it (of converting it to a string).

It can be done with: String.format("%03d", x) (x being a numerical variable).



Answered By - Maurice Perry
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing