A variational wavefunction with two parameters is proposed for the two-dimensional electron gas (2DEG). The new wavefunction does not contain noninteger power of coordinate, and all integrals involving wavefunction can be analytically evaluated. This overcomes the shortcoming of the one proposed by Grinberg [Phys. Rev. B 32, 4028 (1985)] which contains noninteger power of coordinate. The parameters have been determined by minimizing the average energy of an electron. The numerical results of energy and average separation of carriers for the ground state are in excellent agreement with the exact self-consistent (sc) results with average errors 0.21% and 0.57%. The accuracy is several times better than the wavefunction proposed of Grinberg with average errors 1.07% and 1.41%. The results also show that the triangular approximation for electric potential is correct as the density of 2DEG is low, but it deviates from the real situation as the density of 2DEG is high.