pad zero in front of long value?
-
morning, when the string got convert to long, it lost the leading zero, could it just be padded back or it should be converted back to string to add the zero? here is the code, sorry, it's java String t = party.getNumber().getNNxx(); t = rightTrim( t.substring( offset, t.length() ) ); while( t.length() > 0 ) { long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); t = t.substring( 0, t.length()-1 ); String szCountry = Long.toString( party.getCountry() ); long token = cintCity.find( (long) party.getCountry(), city ); if ( token != cintCity.end() ) { party.setCityCode( city ); thanks. -- modified at 12:08 Friday 21st October, 2005
-
morning, when the string got convert to long, it lost the leading zero, could it just be padded back or it should be converted back to string to add the zero? here is the code, sorry, it's java String t = party.getNumber().getNNxx(); t = rightTrim( t.substring( offset, t.length() ) ); while( t.length() > 0 ) { long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); t = t.substring( 0, t.length()-1 ); String szCountry = Long.toString( party.getCountry() ); long token = cintCity.find( (long) party.getCountry(), city ); if ( token != cintCity.end() ) { party.setCityCode( city ); thanks. -- modified at 12:08 Friday 21st October, 2005
I'm not sure why you asked a Java question in a C++ forum.
valerie99 wrote:
when the string got convert to long, it lost the leading zero, could it just be padded back...
No. Numbers with leading zeros are for display purposes only. If you had:
char *szNumber = "01234";
and you assigned that to a
long
via:long lNumber = atol(szNumber);
why would you want
lNumber
to be equal to 01234 instead of 1234?
"Take only what you need and leave the land as you found it." - Native American Proverb
-
morning, when the string got convert to long, it lost the leading zero, could it just be padded back or it should be converted back to string to add the zero? here is the code, sorry, it's java String t = party.getNumber().getNNxx(); t = rightTrim( t.substring( offset, t.length() ) ); while( t.length() > 0 ) { long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); t = t.substring( 0, t.length()-1 ); String szCountry = Long.toString( party.getCountry() ); long token = cintCity.find( (long) party.getCountry(), city ); if ( token != cintCity.end() ) { party.setCityCode( city ); thanks. -- modified at 12:08 Friday 21st October, 2005
-
I'm not sure why you asked a Java question in a C++ forum.
valerie99 wrote:
when the string got convert to long, it lost the leading zero, could it just be padded back...
No. Numbers with leading zeros are for display purposes only. If you had:
char *szNumber = "01234";
and you assigned that to a
long
via:long lNumber = atol(szNumber);
why would you want
lNumber
to be equal to 01234 instead of 1234?
"Take only what you need and leave the land as you found it." - Native American Proverb
-
I'm not sure why you asked a Java question in a C++ forum.
valerie99 wrote:
when the string got convert to long, it lost the leading zero, could it just be padded back...
No. Numbers with leading zeros are for display purposes only. If you had:
char *szNumber = "01234";
and you assigned that to a
long
via:long lNumber = atol(szNumber);
why would you want
lNumber
to be equal to 01234 instead of 1234?
"Take only what you need and leave the land as you found it." - Native American Proverb
-
thanks, David. I need that 0 because it's the phone number, 0123 is different as 123 in some country's city code.......thanks for your help.
Ok, but how are you using that number? Are you sending it to a modem for dialing purposes?
"Take only what you need and leave the land as you found it." - Native American Proverb
-
Ok, but how are you using that number? Are you sending it to a modem for dialing purposes?
"Take only what you need and leave the land as you found it." - Native American Proverb
I think this shouldn't been done as long since it's for display not conculation, leading zero is meaningful at this point. I could left pad zero in front of string, long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); String szcity = utils.leftPadZeros( String.valueOf( city ), t.length()); long token = cintCity.find2( szCountry, szcity ); but the whole app is using long for citycode, it might cause problem later on party.setCityCode( city ); so I was wondering if I could pad zero in front of long....seems like impossible... thanks, have a good weekend