Given two floating point numbers a and b, find a%b.
 
Example 1:
Input:
a = 36.5, b = 5.0
Output:
1.5
Explanation:
36.5 % 5.0 = 1.5
Example 2:
Input:
a = 9.7, b = 2.3
Output:
0.5
Explanation:
9.7 % 2.3 = 0.5
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function floatMod() which takes 2 doubles a, and b as input and returns a%b.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= a,b<= 10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3



class Solution:

    def floatMod(self, a, b):

        # code here

Solutions:
class Solution:

	def floatMod(self, a, b):
		output = round(a % b, 6)
		return output if output != int(output) else int(output)


import math

class Solution:

	def floatMod(self, a, b):
		if a == b:
			return 0

		def helper(x):
			count = 0
			n = False
			for i in str(x):
				if n:
					count += 1
				if i == '.':
					n = True
			return count
		t = max(helper(a), helper(b))
		x = a % b
		ans = round(x, t)
		if int(ans) == ans:
			return int(ans)
		return ans


class Solution:

	def floatMod(self, a, b):
		d = a % b
		if d == 0:
			return 0
		e = str(a).split('.')
		f = str(b).split('.')
		g = max(len(e[1]), len(f[1]))
		x = round(d, g)
		if x - int(x) == 0:
			return int(x)
		return x
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = map(float, input().split())
		ob = Solution()
		print(ob.floatMod(a, b))


from math import fmod

class Solution:

	def floatMod(self, a, b):
		if int(fmod(a, b)) == fmod(a, b):
			return int(fmod(a, b))
		if round(fmod(a, b), 10) == int(round(fmod(a, b), 5)):
			return int(round(fmod(a, b), 10))
		return round(fmod(a, b), 10)


class Solution:

	def floatMod(self, a, b):
		p = str(a).index('.')
		q = str(b).index('.')
		m = max(len(str(a)[p + 1:]), len(str(b)[q + 1:]))
		a = a % b
		a = round(a, m)
		if a % 1 == 0:
			return int(a)
		return a


from math import fmod

class Solution:

	def floatMod(self, a, b):
		p = str(a).index('.')
		q = str(b).index('.')
		m = max(len(str(a)[p + 1:]), len(str(b)[q + 1:]))
		a = a % b
		a = round(a, m)
		if a % 1 == 0:
			return int(a)
		return a