- Home /
How can I get correct figure from formula of float
Debug.Log display correct formula but actually the position of object is not. When Debug.Log display 0.01xxxx the object moves to x=1.xxxx. When Debug.Log display 0.009xxx object moves to 9.xxx. How can I solve this problem? I'm so sorry for my rude English.
using System.Collections; using System.Collections.Generic; using UnityEngine; using System;
public class moveWall : MonoBehaviour { // Start is called before the first frame update void Start() {
 }
 // Update is called once per frame
 void Update()
 {
     var sin = Math.Sin(3*(Time.time));
     Transform myTransform = this.transform;
     Vector3 pos = myTransform.position;
     pos.x = (float)(0.00836 + (sin+1)*0.00157);
     myTransform.position = pos; //this line has problems
     Debug.Log(pos.x);
 }
}
Answer by Bunny83 · Nov 12, 2019 at 01:28 PM
I think I don't really understand your problem. Do you mean that the Debug.Log output is different / not what you expect? Or do you mean that your object is not located at the wanted position? Your object will move on the x axis from 0.00836 up to 0.0115 and back.
If numbers get too small they are displayed using scientific notation. Maybe you have trouble reading scientific notation? The number 9.123E-3 is the same as 0.009123. It's essentially 9.123  10^-3 which is 9.123  0.001 which is 0.009123
If you don't want to print the number in scientific notation you can use:
 Debug.Log(pos.x.ToString("0.########"));
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                