Fractional Part#
Math / Arithmetic / Fractional Part
Can Read
Cannot Write
Description#
The decimal part of a number, without its integer portion
Parameters#
| Name | Description |
|---|---|
| Number | The number the decimal part is taken from |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Fractional Part")]
[Category("Math/Arithmetic/Fractional Part")]
[Description("The decimal part of a number, without its integer portion")]
[Image(typeof(IconPercent), ColorTheme.Type.Yellow)]
[Parameter("Number", "The number the decimal part is taken from")]
[Keywords("Decimal", "Remainder", "Frac", "Modulus", "Part")]
[Serializable]
public class TypeNumberMathFraction : TypeNumber
{
[SerializeField] private GetNumber m_Number = new GetNumber();
public override double GetPreview(GameObject source) => Fraction(this.m_Number.GetPreview(source));
public override double Get(Args args) => Fraction(this.m_Number.Get(args));
private static double Fraction(double number)
{
return number - Math.Truncate(number);
}
public override string ToString()
{
return $"Fraction({this.m_Number})";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}