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

Friday, August 12, 2022

[FIXED] How do i validate it so that the first 3 digits range 100-300(inclusive) and the second 3 digits range 001-999(inclusive) in the following

 August 12, 2022     decimal, java     No comments   

Issue

private boolean validateSno(double inSno) {
  //sno is the serial number


  int firstThree=(int)inSno;
  double secondThree=(inSno-firstThree)*1000;
  boolean same=false;
  double checkDigit=inSno*1000-(int)inSno;

  if(checkDigit>0.0)
  {
  same=false;
  }
  else 
  {
      if(firstThree>=100&&firstThree<=300)
      {
      if(secondThree>=001&&secondThree<=999)
      {
          same=true;
      }

      }
  }
  return same;
}

I need the result to be in form XXX.YYY but as it is a real number I am stuck on how to split the first 3 numbers and the second 3 numbers. Each has its own validation required

is there an easy way using mod/div or?


Solution

For example number 456.234

double number = 456.234;
double firstThree = (int)number; \\ output 456
double lastThree = (number * 1000 % 1000); \\ output 234


Answered By - MrHolal
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • 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