#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Computing 1x where x is positive and value printed is 0.0

Member Posts: 2
I am having a problem computing 1x where x is a positive integer and getting the value in the format of 0.0 with 3 decimal digits.

• Member Posts: 1,666
: I am having a problem computing 1x where x is a positive integer and getting the value in the format of 0.0 with 3 decimal digits.
:

I'm not sure exactly what you are going for so I'm just going to quickly give you a hint on how to display 1/x where x is a positive integer.

1/3=.333... .333... get trucated off we get 0
10/3=3.333... .333... gets truncated off we get 3
100/3=33.333... .333... gets truncated off we get 33

You should be able to figure it out from there.

If this isn't just an exercise in fixed point math or just assembly then I'd suggest using the standard C function printf instead.

"We can't do nothing and think someone else will make it right."

• Member Posts: 2
Thanks for responding. What I am looking for is this. My program that I wrote divides 1x, if I put in x=4, it gives me the value 2. What I need for it to do is multiply 1 * 10 if denominator is greater than numerator and count how many times it does this and then place that amount of decimal spaces in the output value such as count =3 then output value is 0.250, because 14 is .25.

: : I am having a problem computing 1x where x is a positive integer and getting the value in the format of 0.0 with 3 decimal digits.
: :
:
: I'm not sure exactly what you are going for so I'm just going to quickly give you a hint on how to display 1/x where x is a positive integer.
:
: 1/3=.333... .333... get trucated off we get 0
: 10/3=3.333... .333... gets truncated off we get 3
: 100/3=33.333... .333... gets truncated off we get 33
:
: You should be able to figure it out from there.
:
: If this isn't just an exercise in fixed point math or just assembly then I'd suggest using the standard C function printf instead.
:
: "We can't do nothing and think someone else will make it right."
:
:

• Member Posts: 620
[b][red]This message was edited by blitz at 2002-10-26 2:5:13[/red][/b][hr]
: Thanks for responding. What I am looking for is this. My program that I wrote divides 1x, if I put in x=4, it gives me the value 2. What I need for it to do is multiply 1 * 10 if denominator is greater than numerator and count how many times it does this and then place that amount of decimal spaces in the output value such as count =3 then output value is 0.250, because 14 is .25.
:

Here's some C code to put you on the track:
[code]
void puts_1_x(int x)
{
const int DECIMALS = 3;
char buff[DECIMALS + 3] = "0.";

for (int i = 0, y = 10; i < DECIMALS; ++i) {
div_t d = div(y, x);
buff[i + 2] = d.quot + '0';
y = d.rem * 10;
}

puts(buff);
}
[/code]

• USAMember Posts: 4,624 ✭✭

_________ < http://forcoder.org /> free ebooks and video tutorials about [ Go, R, C++, Ruby, PHP, Perl, C, JavaScript, MATLAB, Delphi, C#, Visual Basic, Scratch, Assembly, Swift, Objective-C, Visual Basic .NET, Java, PL/SQL, Python Julia, Awk, Bash, D, F#, Apex, Scheme, VBScript, Dart, ML, LabVIEW, ABAP, Alice, Hack, Lua, Clojure, FoxPro, Crystal, Ada, Erlang, SAS, Prolog, Kotlin, Transact-SQL, Lisp, Logo, Rust, Fortran, Scala, COBOL ] _____