javascript round decimal to preferred number of decimal places
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
Achievement provides the only real pleasure in life
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
Posted by
SF
at
8:33 pm
0
comments
$(function () {
$('.decimal10n2').keyup(function () {
if (!$(this).val().match(/./gi) || !$(this).val().match(/[0-9]+/g)) {
$(this).val("");
}
else if ($(this).val().split('.').length - 1 > 1)
{
this.value = $(this).val().slice(0, -1);
}
else if ($(this).val().indexOf('.') != -1) {
if($(this).val().split(".")[0].length > 10)
{
if (isNaN(parseFloat(this.value))) return;
this.value = $(this).val().split(".")[0].slice(0,-1);
}
else if ($(this).val().split(".")[1].length > 2) {
if (isNaN(parseFloat(this.value))) return;
this.value = parseFloat(this.value).toFixed(2);
}
}
return this;
});
});
Posted by
SF
at
8:32 pm
0
comments
$(document).ready(function () {
$(".navbar-sub-opener").click(function (evt) {
//close submenu when click away - part 2
evt.stopPropagation();
//hide all submenus
$(".navbar-sub").hide();
//only open the one that's immediate inside the clicked parent menu item
$(this).next($(".navbar-sub")).show();
});
//close submenu when click away - part 1
$('html').click(function () {
$(".navbar-sub").hide();
});
});
Posted by
SF
at
10:58 pm
0
comments
jQuery.fn.center = function () {
this.css("position", "fixed");
this.css("top", ($(window).height() / 2) - (this.outerHeight() / 2));
this.css("left", ($(window).width() / 2) - (this.outerWidth() / 2));
return this;
}
Posted by
SF
at
12:55 am
0
comments
required javascript:
$(document).ready(function () {
$(".popupformContainer").dialog({
height: 600,
width: 300,
autoOpen: false,
modal: true,
open: function (event, ui) {
$(this).load("/controllername/actionname", { "parameter": $(this).data("parametervalue") }, function (html) {
});
},
close: function (event, ui) {
event.preventDefault();
alert("closing");
},
buttons: {
text: "提交", click: function (event) {
event.preventDefault();
$.validator.unobtrusive.parse("#PopupForm");
$("#PopupForm").validate();
if ($("#PopupForm").valid()) {
$("#PopupForm").submit();
}
else {
event.preventDefault();
alert("invalid");
}
}
}
});
$(".btnOpenPopupForm").click(function () {
$(".popupformContainer").data("parameter", $(this).attr("value")).dialog("open");
});
});
in the parent view you need the button to open popup with class "btnOpenPopupForm" and an empty div with class "popupformContainer" for hosting the popup
Posted by
SF
at
3:41 am
0
comments
update student
set isOdd = 1, isEven = 0
where exammark % 2 =1
Posted by
SF
at
1:54 am
0
comments
return Redirect(Request.UrlReferrer.ToString());
Posted by
SF
at
12:14 am
0
comments
make sure the form declaration in the view has all necessary attributes, e.g.
Posted by
SF
at
5:26 pm
0
comments
http://jsfiddle.net/r77K8/1/
Posted by
SF
at
5:25 pm
0
comments
public void UploadProductImage(HttpPostedFileBase file)
{
string subPath = "~/Images/";
bool isExists = System.IO.Directory.Exists(Server.MapPath(subPath));
if (!isExists)
{
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
}
if (file != null)
{
string pic = System.IO.Path.GetFileName(file.FileName);
string path = System.IO.Path.Combine(Server.MapPath(subPath), pic);
file.SaveAs(path);
UploadProductImageThumbnail(file, productId);
}
}
public void UploadProductImageThumbnail(HttpPostedFileBase file)
{
using (var image = Image.FromStream(file.InputStream, true, true))
{
var thumbWidth = 50;
var thumbHeight = 50;
using (var thumb = image.GetThumbnailImage(
thumbWidth,
thumbHeight,
() => false,
IntPtr.Zero))
{
var jpgInfo = ImageCodecInfo.GetImageEncoders()
.Where(codecInfo => codecInfo.MimeType == "image/jpeg").First();
using (var encParams = new EncoderParameters(1))
{
string thumbPath = "~/Images/Thumbnails";
bool isExists = System.IO.Directory.Exists(Server.MapPath(thumbPath));
if (!isExists)
{
System.IO.Directory.CreateDirectory(Server.MapPath(thumbPath));
}
var thumbPathFull = Path.Combine(Server.MapPath(thumbPath), file.FileName);
long quality = 100;
encParams.Param[0] = new EncoderParameter(Encoder.Quality, quality);
thumb.Save(thumbPathFull, jpgInfo, encParams);
}
}
}
}
Posted by
SF
at
5:28 pm
0
comments
products = products.Where(p => SqlFunctions.StringConvert((double)p.ProductId).Trim() == searchString);
Posted by
SF
at
12:10 am
0
comments
protected void RadGrid1_DataBound(object sender, eventargs e)
{
GridItem commandItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
Button button1 = commandItem.FindControl("button1") as Button;
}
Posted by
SF
at
12:57 pm
0
comments
string script = "function f(){$find(\"" + RadWindow1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", script, true);
Posted by
SF
at
12:08 pm
0
comments
alternative is to use plain javascript, doesn't behave as nice but it works.
function toggleCourseDescriptions(conditioner) {
var targetCtrl = document.getElementById("divCourseDescription");
var triggerControl = document.getElementById("aToggleCourseDescription");
if (targetCtrl.style.display == 'none') {
targetCtrl.style.display = null;
} else {
targetCtrl.style.display = 'none';
}
if (triggerControl.text == "-") {
triggerControl.text = "+";
} else {
triggerControl.text = "-";
}
}
Posted by
Unknown
at
5:33 pm
0
comments
((int)(((decimal)(a.Category.Sum(l => l.Quantity) : 0) / MyDividerInteger) * 100)).ToString() + "%",
Posted by
Unknown
at
11:40 pm
0
comments
MenuItem item = menu.FindName("ContextMenuItemToggleReporting") as MenuItem;// .Single(i=>((MenuItem)item).Name == "ContextMenuItemToggleReporting") as MenuItem;
if ([you condition logic here. e.g. MyEntity.IsReportingEnabled])
{
item.Header = "Disable Reporting";
}
else
{
item.Header = "Enable Reporting";
}
Posted by
Unknown
at
11:12 pm
0
comments
Posted by
Unknown
at
12:33 pm
0
comments
I have a relative layout with a scrollview and a AdMob in it. The AdMob on the bottom overlaps the the scrollview so that the bottom part of the scrollview can never be seen. After a lot of trial and error I found that the solution is simple: set the ScrollView to android:layout_above="@+id/adView".
So the layout structure is something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView_home"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/adView"
android:layout_alignParentTop="true"
android:background="@drawable/background"
android:orientation="vertical" >
.....
.....
.....
</ScrollView>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="abcdefg"
ads:loadAdOnCreate="true" />
</RelativeLayout>
Posted by
Unknown
at
1:08 am
0
comments
Posted by
Unknown
at
12:25 am
0
comments