Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

Formatting SS#

Need to format Social Security number but the DataFormatString is not cmoing out right... I have {0:###-##-####}. The value in the DB is just a number, no dashes, but I want to display it as a SS#. I formatted the dates to show MM-dd-yyyy, so why isn't the SS# coming up?
0
marcivry
Asked:
marcivry
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
It sounds like it might not be treating you value as a number. Take this as an example:

    int ss = 123456789;
    string formattedSS = string.Format("{0:###-##-####}", ss);

Or in VB:

    Dim ss As Integer = 123456789
    Dim formattedSS As String = String.Format("{0:###-##-####}", ss)
0
 
RamuncikasCommented:
Where should your SS# appear? GridView?
0
 
dfu23Commented:
The pound (#) signs are for displaying numeric data ... and even though the SS# is a bunch of numbers the dashes are what is throwing things off.

I would just split out the parts of the string as needed to make the display you want since the data will always be the same length:

mySSN.Substring(0, 3) + "-" + mySSN.Substring(3, 2) + "-" + mySSN.Substring(5);
0
 
marcivryAuthor Commented:
So, How should I code it? Is it within the script tags or should i do a code behind?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now