Though question seems to be simple, I am trying to concatenate Integer and String by converting integer to string, My formula in DAX :
var storedata=450
var hours = QUOTIENT(storedata, 60)
var minutes = storedata - hours*60
Return
FORMAT(hours,"")+":"+FORMAT(minutes,"")
Format function throws error can't convert type string to type number
But as per the documentation format function converts number to string but here error is totally opposite.
How can I convert Integer to String and concatenate.
Thanks
You can use the function concatenate to return the result as a string:
Measure 4 = var storedata=450
var hours = QUOTIENT(storedata, 60)
var minutes = storedata - hours*60
Return
CONCATENATE(CONCATENATE(FORMAT(hours,""),":"),FORMAT(minutes,""))
This can solve your problem?
Related
I need help with with three regular expressions for date validation. The date formats to validate against should be:
- MMyy
- ddMMyy
- ddMMyyyy
Further:
I want the regular expressions to match the exact number of digits in the formats above. For instance, January should be 01, NOT 1:
060117 // ddMMyy format: Ok
06117 // ddMMyy format: NOT Ok
Hyphens and slashes are NOT allowed, like: 06-01-17, or 06/01/17.
Below are the regex:es that I use. I cannot get them quite right though.
string regex_MMyy = #"^(1[0-2]|0[1-9]|\d)(\d{2})$";
string regex_ddMMyy = #"^(0[1-9]|[12]\d|3[01])(1[0-2]|0[1-9]|\d)(\d{2})$";
string regex_ddMMyyyy = #"^(0[1-9]|[12]\d|3[01])(1[0-2]|0[1-9]|\d)(\d{4})$";
var test_MMyy_1 = Regex.IsMatch("0617", regex_MMyy); // Pass
var test_MMyy_2 = Regex.IsMatch("617", regex_MMyy); // Pass, do NOT want this to pass.
var test_ddMMyy_1 = Regex.IsMatch("060117", regex_ddMMyy); // Pass
var test_ddMMyy_2 = Regex.IsMatch("06117", regex_ddMMyy); // Pass, do NOT want this to pass.
var test_ddMMyyyy_1 = Regex.IsMatch("06012017", regex_ddMMyyyy); // Pass
var test_ddMMyyyy_2 = Regex.IsMatch("0612017", regex_ddMMyyyy); // Pass, do NOT want this to pass.
(If anyone could take allowed days for each month, and leap years into account, that would be a huge bonus :)).
Thanks,
Best Regards
I am working on a project in ActionScript3. I have this function that parses a time-stamp string.
private function convertTimestampToNumber(timestamp:String):Number {
//YYYY-MM-DD HH:mm:SS:sss
var re:RegExp = /(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})\s(?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2})\.(?P<msec>\d{3})/;
var result:Array = re.exec(timestamp);
Alert.show(timestamp, "Timestamp string", Alert.OK);
return (10000000000000 * parseInt(result.year)
+ 100000000000 * parseInt(result.month)
+ 1000000000 * parseInt(result.day)
+ 10000000 * parseInt(result.hour)
+ 100000 * parseInt(result.min)
+ 1000 * parseInt(result.sec)
+ parseInt(result.msec));
}
This seems to work fine for all time-stamps except "2016-08-01 09:19:43.23". Here it throws an error:
[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.
I thought since the millisecond part of this time-stamp is only 2 chars long, it was throwing error. To fix this I changed the millisecond part of the regular expression to (?P<msec>\d{2|3}) thinking that now it would consider both 2-character and 3-character long millisecond as valid, but now it throws the same error on "2015-11-19 15:28:29.737".
What will be the correct regular expression that can consider both scenarios as valid?
Your change is almost right. What you can do is this:
(?P<msec>\d{1,3})
Which will match any number of milliseconds, from 1 digit (possible, though unlikely to appear) to 3.
I'm not sure to understand your question, but if you use de Date Class, you may format your result as you want.
Check and adapt the DateTimeFormatter code here bellow
And check for setDateTimePattern() method too.:
import flash.utils.getTimer;
import flash.globalization.DateTimeFormatter;
import flash.globalization.DateTimeStyle;
var currentTime = new Date();
function formatDate(date:Date) {
var dtf:DateTimeFormatter = new DateTimeFormatter("fr-FR");
// or new DateTimeFormatter("en-EN");
dtf.setDateTimePattern("yyyy-MM-dd hh:mm:ss");
var longDate:String = dtf.format(date);
trace(longDate)+getTimer();
//trace(" *** LocaleID requested=" + dtf.requestedLocaleIDName);
//trace(" *** Format requested (" + dtf.getDateTimePattern() + ")");
}
trace(" setDateTimePattern example");
formatDate(currentTime);
// output the current time formated as "yyyy-MM-dd hh:mm:ss"
// no Milliseconds avalaible now!
Just check the reference, and you'll find an answer AMO.
Hope this helps.
I have command output that has been stored in an array of strings, and this numerical value could or could not exist in a string, and if it does exit it can be any integer value. I've tried various methods with regex and parseInt, and I am not getting the desired effect, I believe because of the way the string is encoded. How have others gone about this in the past?
EDIT:
The issue is the string is coming back, encoded as UT8. So the initial string I get is this: disk: 40 Which I can reduce down to: 40 After that however, using a isNaN(decode_utf8(str)) Still produces a true for isNaN. I am not sure exactly how to overcome this
Try testing if a string is a number like this:
var toTest = "232";
if (!isNaN(+toTest)) {
var aNumber = +toTest
console.log('That is a number: ', aNumber)
if it must be a integer you could check like this:
// check if integer ...
var isInt = typeof aNumber === "number" && aNumber % 1 === 0;
}
If you are using latest JavaScript ES6 then isNumber is built in:
Number.isInteger(123) // true
I was trying to have the value as 456,987,214.
But For me it is coming like without comma.
Here is my code, Did i mistake anything
const string price = "^\\d{3},\\d{3},\\d{3}$";
string pricelist = query.price.ToString();
string price1 = "";
if (System.Text.RegularExpressions.Regex.IsMatch(pricelist.ToString(), price))
{
price1 = query.price.ToString();
}
I noticed it, it is number what you intended to format why not using angular built-in formatting feature like: {{price | number}}
Online Demo
If you want to format this with C# then you can format it using .Net built-in formatters like:
double value = 1234567890;
Console.WriteLine(value.ToString("#,#", CultureInfo.InvariantCulture));
// outputs 1,234,567,890
Try this simple Method:
Just pass your value like this ,
double value = double.Parse(query.price.ToString());
string price1= value.ToString("#,#", CultureInfo.InvariantCulture);
Output will be like 123,456,789
Try this simple method: Just pass your value like this, then you will get the output as you want.
double value = double.Parse(query.price.ToString());
string price1= value.ToString("#,#", CultureInfo.InvariantCulture);
Output will be like 123,456,789
I have a requirement where i have to remove the drop down items depending upon the start date and end date.
The issue here is, It throws error that input string was not in correct format.
foreach (SPListItem oSPListItemCourse in oSPListItemCollectionCourse)
{
string begginingDate = oSPListItemCourse["Start Date"].ToString();
string finishDate = oSPListItemCourse["End Date"].ToString();
if (( Convert.ToInt32(begginingDate)>=Convert.ToInt32(TxtStartDate.Text) ) || (Convert.ToInt32(finishDate)<= Convert.ToInt32(TxtEndDate.Text)))//input string not in correct format
{
ddlDrop.Items.Remove(ddlDrop.SelectedItem);//how to remove the item from drop down if their date is greater than StartDate and less than EndDate
}
}
Convert the startdate and end date value to DateTime Format rather than to a string.
You are trying to convert date string to integer value. What did you expect as result?
If you want to compare two dates just convert all values to DateTime and compare them.