working on it ...

Filters

Explore Public Snippets

Sort by

Found 874 snippets matching: numeric

    public by cghersi  475219  5  7  0

    C#: Parse a comma separated string into a collection of numeric items

    This method can be used with any separator you need, just setting the 'separator' input
    public static List<long> ParseIntoListOfLongs(string content, char separator = ',')
    {
        List<long> ids = new List<long>();
    
        if (string.IsNullOrEmpty(content))
            return ids;
    
        string[] strIds = content.Split(separator);
        foreach (string str in strIds)
        {
            long id = -1;
            if (long.TryParse(str, out id))
            {
                if (id > 0)
                    ids.Add(id);
            }
        }
    
        return ids;
    }
    

    public by p.kontalis  2764  1  5  0

    Numeric Validation on TextFields

    Imports System.Globalization
    Public Class Form 1
    
      Private Sub SheetFromWeight_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim YourPreferableCulture as String = "en-US"
        CultureInfo.DefaultThreadCurrentCulture = New CultureInfo(YourPreferableCulture)
        CultureInfo.DefaultThreadCurrentUICulture = New CultureInfo(YourPreferableCulture)
      End Sub
      
      Private Sub Numbers_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged,
                                                                                   TextBox2.TextChanged,
                                                                                   TextBox3.TextChanged
         If Not IsNumeric(sender.Text) Then sender.text = ""
         If sender.Text.contains(",") Then
              sender.text = sender.text.replace(",", ".")
              sender.select(sender.text.length, 0)
         End If
      End Sub                                  
    End Class

    public by Geometry  1641  1  6  0

    To: Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.

    Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime. The destination type. The value to be converted. The result of the conversion.
    /// <summary>
    ///   Converts an object into another type, irrespective of whether
    ///   the conversion can be done at compile time or not. This can be
    ///   used to convert generic types to numeric types during runtime.
    /// </summary>
    /// 
    /// <typeparam name="T">The destination type.</typeparam>
    /// 
    /// <param name="value">The value to be converted.</param>
    /// 
    /// <returns>The result of the conversion.</returns>
    /// 
    public static T To<T>(this object value)
    {
        if (value is IConvertible)
            return (T)System.Convert.ChangeType(value, typeof(T));
    
        Type type = value.GetType();
        MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
        foreach (var m in methods)
        {
            if ((m.Name == "op_Implicit" || m.Name == "op_Explicit") && m.ReturnType == typeof(T))
                return (T)m.Invoke(null, new[] { value });
        }
    
        return (T)System.Convert.ChangeType(value, typeof(T));
    }

    public by freidamachoi  1969  0  4  0

    AngularJs - sort numeric

    AngularJs - sort numeric: ngSortNumeric.js
    $scope.mySortFunction = function(item) {
     if(isNaN(item[$scope.sortExpression]))
      return item[$scope.sortExpression];
     return parseInt(item[$scope.sortExpression]);
    }
    
    

    public by Geometry  1079  0  5  0

    FromDistributionFunction: Creates a new <see cref="GeneralContinuousDistribution"/> using only a cumulative distribution function definition.

    Creates a new using only a cumulative distribution function definition. The distribution's support over the real line. A cumulative distribution function. The integration method to use for numerical computations. A created from the whose measures and functions are computed using numerical integration and differentiation.
    /// <summary>
    ///   Creates a new <see cref="GeneralContinuousDistribution"/> 
    ///   using only a cumulative distribution function definition.
    /// </summary>
    /// 
    /// <param name="support">The distribution's support over the real line.</param>
    /// <param name="cdf">A cumulative distribution function.</param>
    /// <param name="method">The integration method to use for numerical computations.</param>
    /// 
    /// <returns>A <see cref="GeneralContinuousDistribution"/> created from the 
    /// <paramref name="cdf"/> whose measures and functions are computed using 
    /// numerical integration and differentiation.</returns>
    /// 
    public static GeneralContinuousDistribution FromDistributionFunction(
        DoubleRange support, Func<double, double> cdf, IUnivariateIntegration method)
    {
        GeneralContinuousDistribution dist = new GeneralContinuousDistribution();
        dist.support = support;
        dist.cdf = cdf;
        dist.method = method;
        return dist;
    }

    public by Geometry  1047  0  5  0

    FromDistributionFunction: Creates a new <see cref="GeneralContinuousDistribution"/> using only a cumulative distribution function definition.

    Creates a new using only a cumulative distribution function definition. The distribution's support over the real line. A cumulative distribution function. A created from the whose measures and functions are computed using numerical integration and differentiation.
    /// <summary>
    ///   Creates a new <see cref="GeneralContinuousDistribution"/> 
    ///   using only a cumulative distribution function definition.
    /// </summary>
    /// 
    /// <param name="support">The distribution's support over the real line.</param>
    /// <param name="cdf">A cumulative distribution function.</param>
    /// 
    /// <returns>A <see cref="GeneralContinuousDistribution"/> created from the 
    /// <paramref name="cdf"/> whose measures and functions are computed using 
    /// numerical integration and differentiation.</returns>
    /// 
    public static GeneralContinuousDistribution FromDistributionFunction(
        DoubleRange support, Func<double, double> cdf)
    {
        var method = createDefaultIntegrationMethod();
        return FromDistributionFunction(support, cdf, method);
    }

    public by Geometry  819  0  4  0

    FromDistribution: Creates a new <see cref="GeneralContinuousDistribution"/> from an existing <see cref="UnivariateContinuousDistribution"> continuous distribution</see>.

    Creates a new from an existing continuous distribution. The distribution. A representing the same but whose measures and functions are computed using numerical integration and differentiation.
    /// <summary>
    ///   Creates a new <see cref="GeneralContinuousDistribution"/> 
    ///   from an existing <see cref="UnivariateContinuousDistribution">
    ///   continuous distribution</see>.
    /// </summary>
    /// 
    /// <param name="distribution">The distribution.</param>
    /// 
    /// <returns>A <see cref="GeneralContinuousDistribution"/> representing the same
    /// <paramref name="distribution"/> but whose measures and functions are computed
    /// using numerical integration and differentiation.</returns>
    /// 
    public static GeneralContinuousDistribution FromDistribution(UnivariateContinuousDistribution distribution)
    {
        GeneralContinuousDistribution dist = new GeneralContinuousDistribution();
        dist.support = distribution.Support;
        dist.pdf = distribution.ProbabilityDensityFunction;
        dist.cdf = distribution.DistributionFunction;
        return dist;
    }

    public by Geometry  803  0  4  0

    FromDensityFunction: Creates a new <see cref="GeneralContinuousDistribution"/> using only a probability density function definition.

    Creates a new using only a probability density function definition. The distribution's support over the real line. A probability density function. The integration method to use for numerical computations. A created from the whose measures and functions are computed using numerical integration and differentiation.
    /// <summary>
    ///   Creates a new <see cref="GeneralContinuousDistribution"/> 
    ///   using only a probability density function definition.
    /// </summary>
    /// 
    /// <param name="support">The distribution's support over the real line.</param>
    /// <param name="pdf">A probability density function.</param>
    /// <param name="method">The integration method to use for numerical computations.</param>
    /// 
    /// <returns>A <see cref="GeneralContinuousDistribution"/> created from the 
    /// <paramref name="pdf"/> whose measures and functions are computed using 
    /// numerical integration and differentiation.</returns>
    /// 
    public static GeneralContinuousDistribution FromDensityFunction(
        DoubleRange support, Func<double, double> pdf, IUnivariateIntegration method)
    {
        GeneralContinuousDistribution dist = new GeneralContinuousDistribution();
        dist.support = support;
        dist.pdf = pdf;
        dist.method = method;
        return dist;
    }

    public by JKCPR  2302  0  5  0

    Relational Operators

    These are primarily used to compare numeric and date/time types.
    // < less than
    // <= less than or equal to
    // > greater than
    // >= greater than or equal to
    
    SELECT <columns> FROM <table> WHERE <column name> < <value>;
    
    SELECT <columns> FROM <table> WHERE <column name> <= <value>;
    
    SELECT <columns> FROM <table> WHERE <column name> > <value>;
    
    SELECT <columns> FROM <table> WHERE <column name> >= <value>;

    public by msdn  841  7  5  0

    AcceptNumericOnly: Method to accept only numeric (and numerically useful) key codes

    Method to accept only numeric (and numerically useful) key codes
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    
    // Key code constants
    const int KEY_DECIMAL_POINT = 110;
    const int KEY_DASH          = 189;
    const int KEY_PERIOD        = 190;
    
    /// <summary>
    /// Method to accept only numeric (and numerically useful) key codes
    /// </summary>
    private static void AcceptNumericOnly(object sender, KeyEventArgs e)
    {
        e.Handled = !(
            (!((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift
            || (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control
            || (Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
            && ((e.Key >= Key.D0 && e.Key <= Key.D9) || (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9)
               ||  e.Key == Key.Subtract || e.Key == Key.Add || e.Key == Key.Decimal
               ||  e.Key == Key.Home || e.Key == Key.End || e.Key == Key.Delete ||  e.Key == Key.Tab
               ||  e.Key == Key.Enter || e.Key == Key.Escape || e.Key == Key.Back
               || (e.Key == Key.Unknown
                  && (e.PlatformKeyCode == KEY_DECIMAL_POINT
                  ||  e.PlatformKeyCode == KEY_DASH
                  ||  e.PlatformKeyCode == KEY_PERIOD)))
            )
        );
    }
    • Public Snippets
    • Channels Snippets