App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/socialcalc-3.js view on Meta::CPAN
}
else if (valuesubtype=='$') {
valueformat = '[$]#,##0.00';
}
else if (valuesubtype=='dt') {
valueformat = scc.defaultFormatdt;
}
else if (valuesubtype=='d') {
valueformat = scc.defaultFormatd;
}
else if (valuesubtype=='t') {
valueformat = scc.defaultFormatt;
}
else if (valuesubtype=='l') {
valueformat = 'logical';
}
else {
valueformat = "General";
}
}
if (valueformat=="logical") { // do logical format
return value ? scc.defaultDisplayTRUE : scc.defaultDisplayFALSE;
}
if (valueformat=="hidden") { // do hidden format
return " ";
}
// Use format
return SocialCalc.FormatNumber.formatNumberWithFormat(rawvalue, valueformat, "");
}
//
// valueinfo = DetermineValueType(rawvalue)
//
// Takes a value and looks for special formatting like $, %, numbers, etc.
// Returns the value as a number or string and the type as {value: value, type: type}.
// Tries to follow the spec for spreadsheet function VALUE(v).
//
SocialCalc.DetermineValueType = function(rawvalue) {
var value = rawvalue + "";
var type = "t";
var tvalue, matches, year, hour, minute, second, denom, num, intgr, constr;
tvalue = value.replace(/^\s+/, ""); // remove leading and trailing blanks
tvalue = tvalue.replace(/\s+$/, "");
if (value.length==0) {
type = "";
}
else if (value.match(/^\s+$/)) { // just blanks
; // leave type "t"
}
else if (tvalue.match(/^[-+]?\d*(?:\.)?\d*(?:[eE][-+]?\d+)?$/)) { // general number, including E
value = tvalue - 0; // try converting to number
if (isNaN(value)) { // leave alone - catches things like plain "-"
value = rawvalue + "";
}
else {
type = "n";
}
}
else if (tvalue.match(/^[-+]?\d*(?:\.)?\d*\s*%$/)) { // percent form: 15.1%
value = (tvalue.slice(0, -1) - 0) / 100; // convert and scale
type = "n%";
}
else if (tvalue.match(/^[-+]?\$\s*\d*(?:\.)?\d*\s*$/) && tvalue.match(/\d/)) { // $ format: $1.49
value = tvalue.replace(/\$/, "") - 0;
type = "n$";
}
else if (tvalue.match(/^[-+]?(\d*,\d*)+(?:\.)?\d*$/)) { // number format ignoring commas: 1,234.49
value = tvalue.replace(/,/g, "") - 0;
type = "n";
}
else if (tvalue.match(/^[-+]?(\d*,\d*)+(?:\.)?\d*\s*%$/)) { // % with commas: 1,234.49%
value = (tvalue.replace(/[%,]/g, "") - 0) / 100;
type = "n%";
}
else if (tvalue.match(/^[-+]?\$\s*(\d*,\d*)+(?:\.)?\d*$/) && tvalue.match(/\d/)) { // $ and commas: $1,234.49
value = tvalue.replace(/[\$,]/g, "") - 0;
type = "n$";
}
else if (matches=value.match(/^(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{1,4})\s*$/)) { // MM/DD/YYYY, MM/DD/YYYY
year = matches[3] - 0;
year = year < 1000 ? year + 2000 : year;
value = SocialCalc.FormatNumber.convert_date_gregorian_to_julian(year, matches[1]-0, matches[2]-0)-2415019;
type = "nd";
}
else if (matches=value.match(/^(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})\s*$/)) { // YYYY-MM-DD, YYYY/MM/DD
year = matches[1]-0;
year = year < 1000 ? year + 2000 : year;
value = SocialCalc.FormatNumber.convert_date_gregorian_to_julian(year, matches[2]-0, matches[3]-0)-2415019;
type = "nd";
}
else if (matches=value.match(/^(\d{1,2}):(\d{1,2})\s*$/)) { // HH:MM
hour = matches[1]-0;
minute = matches[2]-0;
if (hour < 24 && minute < 60) {
value = hour/24 + minute/(24*60);
type = "nt";
}
}
else if (matches=value.match(/^(\d{1,2}):(\d{1,2}):(\d{1,2})\s*$/)) { // HH:MM:SS
hour = matches[1]-0;
minute = matches[2]-0;
second = matches[3]-0;
if (hour < 24 && minute < 60 && second < 60) {
value = hour/24 + minute/(24*60) + second/(24*60*60);
type = "nt";
}
}
else if (matches=value.match(/^\s*([-+]?\d+) (\d+)\/(\d+)\s*$/)) { // 1 1/2
intgr = matches[1]-0;
num = matches[2]-0;
denom = matches[3]-0;
if (denom && denom > 0) {
( run in 1.536 second using v1.01-cache-2.11-cpan-ad19def0cd9 )